How to make GAE+ django pick up my .po and .mo tra

2019-07-18 06:35发布

I got translations ready in .po and .mo files. How can I make django 1.2 display these? I can use the builtin trnanslations and now I want to enable in addition the ones I keep in [application-name]/conf/locale/[Language_Code]/LC_MESSAGES'

Is there a way? It used to work with django 0.96 and after the upgrade only the builtin translations work.

UPDATE: I tried moving to APP_DIR/locale/LANG_CODE/LC_MESSAGES/django.po and it won't work for me. Maybe I missed something. Do I have to recompile .po files?

UPDATE: Folowing the instructions here, I put my .po and .mo files in

APP_DIR/locale/LANG_CODE/LC_MESSAGES/django.po

It still won't work. I'm considering why and welcoming any more advice or recommendation how to enable i18n features with django for google app engine.

EDIT: Here's a link where we discuss this issue in the GAE python group.

Update: Now it works. We didn't have to move around the directories in the conf directory. We just use:

from google.appengine.dist import use_library
use_library('django', '1.2')

# Force Django to reload settings
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'conf.settings'
settings._target = None

2条回答
祖国的老花朵
2楼-- · 2019-07-18 07:02

First you should use

'django.middleware.locale.LocaleMiddleware'

in your settings file, but I think you already are aware of that. Next I suggest using ugettext_lazy for translation in your views (i.e. every string 'test' in view should be passed by ugettext_lazy('test')). In templates using {% trans "text" %} should work (remember that templates need to load {% load i18n %}). Then use the script:

django-admin makemessages

in your APP_DIR. Finally edit django.po files and use

django-admin compilemessages

after translations. That's all. Did you tried this? Does it work or not?

查看更多
Ridiculous、
3楼-- · 2019-07-18 07:18

Put you locale files at:

APP_DIR/locale/LANG_CODE/LC_MESSAGES/django.po
APP_DIR/locale/LANG_CODE/LC_MESSAGES/django.mo

I had same problem and changing the path worked

查看更多
登录 后发表回答