2
votes

I am considering switching from natural gettext msgids to fixed ones. E.g. from

        {% trans "Welcome to the site" %}

to

        {% trans "welcome_to_site" %}

This is because text string updates become more and more cumbersomes when the number of languages is growing on the site and going through all the translations for each continuous deployment release is not practical. However, switching to fabricated msgids would making working on the site templates and source code, where English the primary language, cumbersome.

Pyramid framemwork and Chameleon templates offer a neat solution to this problem by allowing default values for gettext translations. E.g. when there isn't a msgid and msgstr data available in (English) .po file you use the default value. Thus you can mix in natural text and msgid to your translations. Example:

         from pyramid.i18n import TranslationString
         ts = TranslationString('add-number', default='Add ${number}',
                            domain='form', mapping={'number':1})

Does anything similar exist to Django?

Alternatively - are there any tools for contextual based translations which would work even if the msgid text does no longer match, by utilizing file and line number information in .po file comments?

If there doesn't exist a solution I was thinking to implement a custom translation function and custom xtrans and xblocktrans template tags which would take a msgid hint.

1

1 Answers

0
votes

Correct me if I'm wrong but I think that this {% trans "Welcome to the site" %} is not english translation, it's just a placeholder string and a default value in case of no translation is found at the same time (I call it "developer's english"). You can provide separate english translations additionally to these "english" strings in the source code. This is the way I understand translations in Django, but feel free to correct me.