我需要在我的项目中实现国际化,所以我想将 i18n 用于静态内容,而我将应用程序 django-modeltranslation 用于模型。我支持以下语言:
en-us (默认) nl-nl de-de fr-fr es-es
虽然我是荷兰人,但 django 不会将语言更改为荷兰语。我确实有一个英文窗口,但 chrome 设置为荷兰语来测试国际化。这不是唯一的问题,只有模型在默认语言更改时会自行翻译。当我将默认语言设置为荷兰语时,所有模型都将显示荷兰语翻译,但静态内容保持为英语。
注意:我确实使用了 compilemessages 并重新启动了服务器
设置.py
USE_I18N = True
LANGUAGE_CODE = 'en-us'
gettext = lambda s: s
LANGUAGES = (
('en-us', gettext('English')),
('nl-nl', gettext('Dutch')),
('fr-fr', gettext('French')),
('de-de', gettext('German')),
('es-es', gettext('Spain')),
)
LOCALE_PATHS = ('/vagrant/locale', )
/vagrant/locale/en-us/LC_MESSAGES/django.po(缩短文件以显示错误)
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-05-17 23:14+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Language: en-us\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: PyDiving/settings.py:170
msgid "English"
msgstr ""
#: PyDiving/settings.py:171
msgid "Dutch"
msgstr ""
#: PyDiving/settings.py:172
msgid "French"
msgstr ""
#: PyDiving/settings.py:173
msgid "German"
msgstr ""
#: PyDiving/settings.py:174
msgid "Spain"
msgstr ""
#: company/templates/company/company_detail.html:22
msgid "City"
msgstr ""
/vagrant/locale/nl-nl/LC_MESSAGES/django.po (仅显示缩短帖子的差异)
"Language: nl-nl\n"
#: company/templates/company/company_detail.html:28
msgid "Postal Code"
msgstr "Postcode"
#: company/templates/company/company_detail.html:34
msgid "City"
msgstr "Stad"
模板公司/templates/company/company_detail.html
{% load i18n %}
{{ company.text }} # this is the model translation, this will change when i change the default language
{% trans "City" %} # this always says "City"
默认语言为 en-us 时的结果
EnglishCity
其中'英语是模型的内容'
默认语言 nl-nl
NederlandsCity