Django为什么不从其他目录中的模板文件生成区域设置文件? [英] Why doesn't Django produce locale files from template files in another directory?

查看:163
本文介绍了Django为什么不从其他目录中的模板文件生成区域设置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

版本信息:

Django版本1.3 pre-alpha SVN-13858

Django version 1.3 pre-alpha SVN-13858

Ubuntu GNU / Linux 10.10

Ubuntu GNU/Linux 10.10

我在Django中完全是i18n和lnn的新手,目前我正在尝试使用荷兰语提供Django项目(除了默认语言:英文) 。我试图应用 http://docs.djangoproject.com发布的说明/ en / dev / topics / i18n / translation / http:// www .djangobook.com / en / 2.0 / chapter19 / ,但我没有成功。我不知道这是否与我的目录结构和模板文件在一个完全不同的目录(我的意思是不是作为我的Django项目目录中的子目录)相关。我的项目目录如下:

I'm totally new to i18n and l10n in Django and currently I'm trying to make my Django project available in Dutch (in addition to its default language: English). I tried to apply the instructions given at http://docs.djangoproject.com/en/dev/topics/i18n/translation/ and http://www.djangobook.com/en/2.0/chapter19/ but I had no success. I don't know if this is related to my directory structure and template files being in a completely different directory (I mean not as a subdirectory within the my Django project directory). My project directory looks like the following:

/home/emre/mydjango/myproject
/home/emre/mydjango/myproject/myapp1
/home/emre/mydjangotemplates
/home/emre/mydjangotemplates/myapp1

在myproject和myapp1目录中,我尝试发出以下命令:

In the myproject and myapp1 directories I tried to issue the following command:

django-admin.py makemessages -l nl

但收到以下错误:

Error: This script should be run from the Django SVN tree or your project or 
app tree. If you did indeed run it from the SVN checkout or your project or 
application, maybe you are just missing the conf/locale (in the django tree)
or locale (for project and application) directory? It is not created automatically,
you have to create it by hand if you want to enable i18n for your project or
application.

所以我尝试在myproject和myapp1目录中创建 locale 目录。之后,我再次发出上述命令(一次在项目中,一次在应用程序目录中),这次没有任何错误或警告,它说:

So I tried to create locale directories within myproject and myapp1 directories. After that I issued the above command again (once in the project and once in the app directory) and this time without any error or warnings it said:

processing language nl

我查看了语言环境目录,看到他们已经填充了sub -directories,但根本没有任何.po文件:

I checked the locale directories and saw that they were populated with sub-directories but there weren't any .po files at all:

$ tree
.
 `-- nl
     `-- LC_MESSAGES

2 directories, 0 files

我重新检查了我在home / emre / mydjangotemplates中有我的.html文件(模板文件),它们包括{%load i18n%},还有一些行,如{%trans一个英文文字%。

I double checked that I have my .html files (template files) in home/emre/mydjangotemplates and that they include {% load i18n %} and some lines like {% trans "A piece of English text" %}.

我缺少什么?我应该调用不同参数的django-admin.py makemessages命令吗?为什么Django不会创建.po文件,即使我有一些文本要在我的.html模板文件中翻译?

What am I missing? Should I invoke the django-admin.py makemessages command with different parameters? Why doesn't Django create .po files even though I have some text to be translated in my .html template files?

推荐答案

makemessages仅查看当前目录下的目录。您可以尝试从您项目的某个地方创建一个符号链接到您的模板目录,并添加 - 使其遵循符号链接

makemessages only looks in directories under the current directory. You can try creating a symlink from somewhere under your project to your templates directory and add the -s to make it follow symlinks.

这篇关于Django为什么不从其他目录中的模板文件生成区域设置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆