Gettext/Django for german translations: formal/inf

2020-04-18 03:17发布

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 fighting with the problem that German differentiates between formal and informal speech (see T–V distinction). Because the app is used on different sites, ranging from a social network to a banking website, I can't just support either the formal or informal version. And since the translations can differ quite a bit, there's no way I can parameterize it. E.g. the sentence "Do you want to log out?" would have these two translations:

  • Wollen Sie sich abmelden? (formal)
  • Willst du dich abmelden? (informal)

Is there anything in Gettext that could help me with this?

2条回答
▲ chillily
2楼-- · 2020-04-18 03:51

You can use contextual markers to give your translations additional context.

logout = pgettext('casual', 'Do you want to log out?')

...

logout = pgettext('formal', 'Do you want to log out?')
查看更多
成全新的幸福
3楼-- · 2020-04-18 03:56

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.

查看更多
登录 后发表回答