Django translations does not work
Solution 1:
I solved my issue. In my case, the problem was with the LOCALE_PATHS
definition in settings.py.
I tested it in the view by :
from TranslationTest import settings
return HttpResponse(settings.LOCALE_PATHS)
It was showing home/myProjects/TranslationTest/TranslationTest/locale
, however makemessages
was producing the files in home/myProjects/TranslationTest/locale
so I changed my settings as follows :
SITE_ROOT = os.path.dirname(os.path.realpath(__name__))
LOCALE_PATHS = ( os.path.join(SITE_ROOT, 'locale'), )
and now it works.
But I still wonder, why didn't makemessages
understand that it should create the files in the LOCALE_PATHS
specificed by settings.py?
In my understanding, it always produces the locale files in SITE_ROOT/locale, so we should always set LOCALE_PATHS to this? If this is a default, why set it at all? I would appreciate further information on this issue.
Thanks for all the help !
Solution 2:
and keep in mind if your language has a country in it e.g. fa-IR, in your settings file you must add:
LANGUAGE_CODE = 'fa-IR'
but when you want to call makemessages command you should change -
to _
:
makemessages -l fa_IR