Vin*_*iso 5 python django translation internationalization
所以我使用 django 1.8 创建一个必须被翻译成葡萄牙语的新网站。
所以要使用 django 自己的工具,我添加到我的中间件中:
'django.middleware.locale.LocaleMiddleware',
Run Code Online (Sandbox Code Playgroud)
我还添加到我的 context_processors:
'django.template.context_processors.i18n',
Run Code Online (Sandbox Code Playgroud)
和我配置我的语言设置:
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
Run Code Online (Sandbox Code Playgroud)
我还在我的文档顶部导入了:
from django.utils.translation import ugettext as _
Run Code Online (Sandbox Code Playgroud)
然后我添加了标签:
{% trans "text" %}
Run Code Online (Sandbox Code Playgroud)
在我的模板上加上适当的文本。之后我跑了:
python manage.py makemessages -l pt-br
Run Code Online (Sandbox Code Playgroud)
然后我翻译了我的 .po 文件中的所有内容,最后我编译了它:
python manage.py compilemessages
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的网站时,它仍然是英文的。我的浏览器在 pt-br 上,我也有一个工作示例,但是这个特定站点没有被翻译。我确实添加了 i18n 网址。
有人可以帮我吗?我错过了什么?