Wednesday, December 21, 2016

How to create Django translations for django-rosetta from a model field

How to create Django translations from a model field for django-rosetta?



I am using Django-Rosetta to handle all of my project translations.  Unfortunately I have only one model and one field of data that needs translation, the name of the POI.  To get around this I have created a little script to query my Django Database directly to deliver the list of names to be translated.  The output is a new html file with "trans" tags.  This html file is then placed in my templates folder so that "makemessages" can find the file and mark them for translation.

Anytime I want to update this I can run this script and bingo, new template file and new translations.

Note to self:  When adding msgid and msgstr  by hand the command "makemessages" will remove them in the .po file every time the command is called.