0
英語またはフランス語(カナダ)で動作するアプリケーションを開発しています。 Djangoの設定は次のとおりです。アプリのポップからDjangoの翻訳が表示されない
LANGUAGE_CODE = 'en'
LANGUAGES = [
('en', gettext('English')),
('fr-ca', gettext('Canadian French')),
]
LOCALE_PATHS = (
...
os.path.join(PROJECT_ROOT, 'console', 'locale'),
...
)
アプリのロケール・パスは、Djangoのデバッグツールバー、および他のアプリは問題なくフランス語を表示している間、アプリはしかし、最近、翻訳の大半をレンダリング停止したconsole/locale/fr-CA/LC_MESSAGES/
です。
たとえば、「名字」、「姓」、「メール」というフォームがあります。昨日、これは正しくpoファイルを使用していました。
#: console/forms/participants.py:631
msgid "First Name"
msgstr "Prénom"
#: console/forms/participants.py:635
msgid "Last Name"
msgstr "Nom"
#: console/forms/participants.py:140 console/forms/participants.py:469
#: console/forms/participants.py:639 console/models/mixins.py:70
msgid "Email"
msgstr "Courriel"
しかし、今日、唯一Email
文字列がフランス語で表示されています。私はシェルでテストしたので、ugettext
は別のアプリケーションから取得していると仮定します。
>>> from django.utils.translation import ugettext, activate
>>> activate('fr-ca')
>>> ugettext('Sunday')
u'dimanche'
>>> ugettext('Event')
u'Event'
>>> ugettext('Yes')
u'Oui'
>>> ugettext('Gender')
u'Gender'
>>> ugettext('enquiry')
u'enquiry'
>>> ugettext('Enquiry')
u'Enquiry'
>>> ugettext('Receive notifications about other events.')
u'Receive notifications about other events.'
これらはすべてアプリケーションのpoファイルから取得したものです。
#: console/models/events.py:35 console/models/events.py:206
#: console/models/participants.py:81 console/models/vouchers.py:14
msgid "Event"
msgstr "Événement"
#: console/models/participants.py:113
msgid "Gender"
msgstr "Sexe"
#: console/models/participants.py:160
msgid "Receive notifications about other events."
msgstr "Recevez des notifications pour un événement."
翻訳管理コマンドを実行したことは言うまでもありません(ロケールパスが出力されていることがわかります)。あなたはgettext
ugettext_lazy
は遅延評価で、モデルやフォームで使用されるべきであることを覚えておいてください manage.py makemessages -l fr-CA
manage.py compilemessages -l fr-CA
大半はテンプレートTと一緒にugettext_lazy使用したモデル&フォームからです