I followed the whole documentation about text translation, but django doesn't take my .mo
file into account.
Some facts:
conf/locale/
folder at the root of my projectdjango.po
was generated successfully with django-admin.py makemessages -l fr
django.mo
was generated successfully with django-admin.py compilemessages
So my folder structure is:
project/
site/
locale/
fr/
LC_MESSAGES/
django.mo
django.po
settings.py
, I have set LANGUAGE_CODE = 'fr'
Accept-Language:fr-FR,fr;
request.LANGUAGE_CODE
shows fr
from my viewsBut I get nothing translated... How to make django take these files into account ?
Adding /home/www/project/locale
to settings.LOCALE_PATHS
works. However, Django should find this path by itself, and I don't like using absolute paths. What happens here ?
LOCALE_PATHS
Django looks for translation files in 3 locations by default:
LOCALE_PATHS/(language)/LC_MESSAGES/django.(po|mo)
$APPPATH/locale/(language)/LC_MESSAGES/django.(po|mo)
$PYTHONPATH/django/conf/locale/(language)/LC_MESSAGES/django.(po|mo)
LOCALE_PATHS only need to be used if your translation files aren't in your app directories or on the PYTHON_PATH.
An example of LOCALE_PATHS in settings.py
LOCALE_PATHS = (
'/home/www/project/conf/locale', # replace with correct path here
)
MIDDLEWARE_CLASSES
Add django.middleware.locale.LocaleMiddleware
to MIDDLEWARE_CLASSES
in settings.py
LANGUAGES
LANGUAGES = (
('fr', 'Français'),
)
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