Gettext/Django for german translations: formal/informal salutations

后端 未结 2 957
借酒劲吻你
借酒劲吻你 2021-01-22 01:16

I maintain a pluggable Django app that contains translations. All strings in Python and HTML code are written in English. When translating the strings to German, I\'m always fig

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-22 01:44

    The best approach, used in other similar situations by gettext as well as UNIX is to use locale variants. For example, sr_RS is (or was, because Serbian is considered a metalanguage these days...) code used for Serbian written in Cyrillic. But it’s sometimes written in Latin script too, so sr_RS@latin is used as the language name and of course, the MO filename or directory as well.

    Here, have a look at some translations I have present on my system:

    $ find /usr/local/share/locale | grep /sr
    /usr/local/share/locale/sr
    /usr/local/share/locale/sr/LC_MESSAGES
    /usr/local/share/locale/sr/LC_MESSAGES/bash.mo
    /usr/local/share/locale/sr/LC_MESSAGES/bfd.mo
    /usr/local/share/locale/sr/LC_MESSAGES/binutils.mo
    /usr/local/share/locale/sr/LC_MESSAGES/gettext-runtime.mo
    /usr/local/share/locale/sr/LC_MESSAGES/gettext-tools.mo
    /usr/local/share/locale/sr/LC_MESSAGES/glib20.mo
    /usr/local/share/locale/sr/LC_MESSAGES/wget.mo
    /usr/local/share/locale/sr@ije
    /usr/local/share/locale/sr@ije/LC_MESSAGES
    /usr/local/share/locale/sr@ije/LC_MESSAGES/glib20.mo
    /usr/local/share/locale/sr@latin
    /usr/local/share/locale/sr@latin/LC_MESSAGES
    /usr/local/share/locale/sr@latin/LC_MESSAGES/glib20.mo
    /usr/local/share/locale/sr_RS
    /usr/local/share/locale/sr_RS/LC_MESSAGES
    /usr/local/share/locale/sr_RS/LC_MESSAGES/mkvtoolnix.mo
    /usr/local/share/locale/sr_RS@latin
    /usr/local/share/locale/sr_RS@latin/LC_MESSAGES
    /usr/local/share/locale/sr_RS@latin/LC_MESSAGES/mkvtoolnix.mo
    $
    

    So the best way to handle German variants is the same: use de (or de_DE) for the base informal variant and have a separate translation file de_DE@formal with the formal variant of the translation.

    This is basically what WordPress does too. Of course, being WordPress, they have their own special flavour and don’t use the variant syntax, but instead add a third component to the filename: de_DE.mo is the informal (and also fallback, because it lacks any further specification) variant and de_DE_formal.mo contains the formal variant.

提交回复
热议问题