4
votes

I work on a Django project where the default language is french. I also want to support english.

The internationalisation works as I expected in python code and template code :

  • when the language requested is french (there is /fr/ in the url), the text displayed is the one from my code (in my case french), even if there is a translation in locale/en/LC_MESSAGES/django.po (that has been compilated into django.mo).
  • when the language requested is english (there is /en/ in the url)
    • if there is a translation in locale/en/LC_MESSAGES/django.po, this translation is displayed
    • if not, the "default" text from my code is displayed

So it seems I don't need to create and compile the message file for my base language (right?).

In the javascript files it does not work the same : it displays the translation from locale/en/LC_MESSAGES/django.po whenever there is one, even when the language requested is french.

After reading this thread, I ran the commands:

django-admin makemessages -d djangojs -l fr
django-admin compilemessages

But I still get the english translation, unless I fill in the msgstr in locale/fr/LC_MESSAGES/djangojs.po.

Do I have to fill in the msgstr for my base language (so basically copy/paste the msgid) for every text of my site?
That seems very tedious.

2

2 Answers

0
votes

Did you try using rosetta? If you use rosetta then it will make your translations much easier.

0
votes

we encountered exactly the same problem, an easy way to fix this was to launch the following command after your django-admin makemessages -d djangojs -l fr

msgen PATH_TO_YOUR_DJANGOJS.PO_FILE -o PATH_OF_YOUR_DESIRED_OUTPUT_FILE

msgen will fill the empty strings with original msgid text, and is an internal tool installed with gettext utility.

Br.