因此,我正在使用django 1.8创建必须转换为葡萄牙语的新网站。
So I'm using django 1.8 to create a new web site that has to be translated into portuguese.
因此,要使用我添加到中间件中的django自己的工具:
So to use django's own tools I added to my middlewares:
'django.middleware.locale.LocaleMiddleware',我还添加了我的context_processors:
I also added to my context_processors:
'django.template.context_processors.i18n',,然后我配置我的语言设置:
and the i configure my language settings:
USE_I18N = True gettext = lambda s: s LANGUAGE_CODE = 'en' LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale'), ) print LOCALE_PATHS LANGUAGES = ( ('pt-br', gettext('Portuguese')), ('en', gettext('English')), ) TIME_ZONE = 'America/Sao_Paulo' USE_L10N = True USE_TZ = True我也已在文档顶部导入:
I also have imported on the top of my document:
from django.utils.translation import ugettext as _然后我添加了标签:
{% trans "text" %}在我的模板上适当的文本。之后,我运行了:
on my templates with the appropriate texts. After that i ran:
python manage.py makemessages -l pt-br然后我翻译了.po文件中的所有内容,最后用以下命令对其进行了编译:
then i translated everything on my .po file, and finally i compiled it with:
python manage.py compilemessages但是当我运行我的网站时还是英文。 我的浏览器位于pt-br上,我也有一个有效的示例,但此特定网站未得到翻译。 我确实添加了i18n网址。
But when I ran my site it was still in english. My Browser is on pt-br, and i also have a working example but this specific site is not being translated. I did add the i18n urls.
有人可以帮助我吗?我缺少什么?
Can anybody help me out? What Am I missing?
推荐答案因此,显然Django必须将语言环境文件夹视为pt_br而不是pt-br,但设置具有与pt-br在一起。那就是我的诀窍。
So Apparently Django has to see the locale folder as pt_br not pt-br, but the settings have to be with pt-br. That's that did the trick for me.
更多推荐
即使使用LOCALE
发布评论