Django translation with priority / fallback language code

I am looking for tips on how best to improve the Django translation structure.

The goal is to change the translation system so that instead of immediately returning to when a match cannot be found, the system first tries to get the translation from another (predefined) language code. msgid

Background:

The desire to first try to retreat into another language, and not because the current set of "msgid" is not readable by humans. The project uses tokens / identifiers. Human-readable English is its own PO file for translation along with all other languages. This is beneficial when it comes to setting up an English copy ... no need to touch other language files. msgids

Attempt:

def ugettext_fb(message):
    trans_output = translation.ugettext(message)

    if trans_output == message:
        preset_language = translation.get_language()
        logger.warn('Missing \'%s\' translation for %s' % (preset_language, message))

        translation.activate(settings.LANGUAGE_FALLBACK)
        trans_output = translation.ugettext(message)
        translation.activate(preset_language)

    return trans_output

, , , , SO ?

, Django, , gettext(_lazy) . ?

+4

All Articles