Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django makemessages decides to comment already existing translations

When I run manage.py makemessages I found some messages which were in the .po file like this:

msgid "Example"
msgstr "Example"

Transformed to this, after I ran the command:

#~ msgid "Example"
#~ msgstr "Example"
  • What does #~ means? Since the translation of those messages doesn't work anymore, I suppose it is a comment.
  • What can I do to prevent Django commenting out (or "#~ing") pre-existing messages in the translation file?
like image 688
Saturnix Avatar asked Sep 23 '15 21:09

Saturnix


People also ask

What is gettext lazy in Django?

gettext_lazy is a callable within the django. utils. translation module of the Django project.

How do I translate text in Django?

Use the function django. utils. translation. gettext_noop() to mark a string as a translation string without translating it.

What is Django PO file?

Finally, we add Locale_paths which is folder inside our app created by django-admin startapp. 4) Make sure you create this folder structure under app's directory. folder structure. This way Django will know where to place generated .po files for each language. PO file is a portable object file, which is text-based.


2 Answers

Django will comment-out all messages that are no longer in your code. It won't remove them, so you won't lose it, but that way this messages won't end up in compiled .mo file.

like image 160
GwynBleidD Avatar answered Oct 04 '22 16:10

GwynBleidD


I was facing a similar problem with 3rd party apps. makemessages did not include them in the .po file and when adding them manually makemessages was commenting them out next time.

In my case I had the virtual env symlinked into the project folder. To make makemessages see those 3rd party apps I had to add -s

./manage.py makemessages -a -s -l de -i faker -i openid -i gunicorn

At the same time I want to exclude some apps from translations with -i

like image 33
djangonaut Avatar answered Oct 04 '22 17:10

djangonaut