Why doesn't Django translation use the base language in javascript?

I am working on a Django project where the default language is French. I also want to support English.

Internationalization works the way I expected in Python code and template:

  • when the requested language is French (the URL is / fr /), the text is displayed in my code (in my case, French), even if there is a translation in locale / en / LC_MESSAGES / django.po (which was compiled in django.mo )
  • when the requested language 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.

It seems to me that I do not need to create and compile a message file for my base language (right?).

It doesn’t work the same in javascript files: it displays the translation from locale / en / LC_MESSAGES / django.po whenever it is, even if the requested language 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 complete msgstr in locale / fr / LC_MESSAGES / djangojs.po.

Should I fill out msgstr for my base language (so basically copy / paste msgid) for every text of my site?
It seems very tiring.

+4
source share
2 answers

rosetta? rosetta, .

0

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

msgen PATH_TO_YOUR_DJANGOJS.PO_FILE -o PATH_OF_YOUR_DESIRED_OUTPUT_FILE

msgen msgid , gettext.

Br.

0

Source: https://habr.com/ru/post/1611930/


All Articles