首页 > 解决方案 > Django:有没有办法用“du”非正式地称呼?

问题描述

与英语相比,您可以用德语与他人交谈有两种不同的“版本”。您可以使用正式的、更客观的“Sie”或非正式的、更私人的“du”。

所以,当你只是说“你能帮帮我吗?” 用英语,你可以说

在德国。

我现在的问题是,对于我的 Django 应用程序,我想使用第二个版本(“du”),因为它更适合我的 Web 应用程序。问题是 Django(我知道什么?)只支持正式版本,现在我在 Web 应用程序中存在不一致。有时,您可以阅读“du”,有时可以阅读“Sie”(来自默认的 Django 翻译)。

当然,我可以用“du”删除我手动添加的句子,但我不喜欢它,因为该网页将面向彼此认识的人。

我的两个问题:

  1. 有没有办法让 Django 使用我可能错过的非正式翻译?
  2. 如果 Django 不提供此功能,有没有办法让 Django 支持它(我很乐意提供/更改翻译)。或者您知道其他解决方案吗?

标签: pythondjango

解决方案


Django's translation system is just gettext, so you have the features of gettext available to you.

The one you probably want here is contextual markers. Django supports this.

So you can mark strings for translation with a contextual marker of 'formal' or 'informal', and this will allow you to supply multiple translations of the string (one for each distinct contextual marker).

So, for example, if you have template code containing both

[% trans "Can you help me?" context "formal" %}

and

{% trans "Can you help me?" context "informal" %}

then your .po file will end up with that string twice, and you can supply the formal and informal translations, and Django will pull the correct one for the context you requested.


推荐阅读