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?
Django's internationalization hooks are on by default, and that means there's a bit of i18n-related overhead in certain places of the framework. If you don't use internationalization, you should take the two seconds to set USE_I18N = False in your settings file.
Django offers multiple language support out-of-the-box. In fact, Django is translated into more than 100 languages. This tutorial looks at how to add multiple language support to your Django project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With