Django Translation not working even with LOCALE_PATHS

有些话、适合烂在心里 提交于 2019-12-22 07:59:13

问题


So I'm using django 1.8 to create a new web site that has to be translated into portuguese.

So to use django's own tools I added to my middlewares:

'django.middleware.locale.LocaleMiddleware',

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 _

Then i added the tags:

{% trans "text" %}

on my templates with the appropriate texts. After that i ran:

python manage.py makemessages -l pt-br

then i translated everything on my .po file, and finally i compiled it with:

python manage.py compilemessages

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?


回答1:


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.



来源:https://stackoverflow.com/questions/32402752/django-translation-not-working-even-with-locale-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!