问题
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