python - Django:有没有办法用“du”非正式地称呼?
问题描述
与英语相比,您可以用德语与他人交谈有两种不同的“版本”。您可以使用正式的、更客观的“Sie”或非正式的、更私人的“du”。
所以,当你只是说“你能帮帮我吗?” 用英语,你可以说
- Können Sie mir helfen? (正式,当你并不真正了解这个人时)
- Kannst du mir helfen?(非正式的,当你已经认识这个人时)
在德国。
我现在的问题是,对于我的 Django 应用程序,我想使用第二个版本(“du”),因为它更适合我的 Web 应用程序。问题是 Django(我知道什么?)只支持正式版本,现在我在 Web 应用程序中存在不一致。有时,您可以阅读“du”,有时可以阅读“Sie”(来自默认的 Django 翻译)。
当然,我可以用“du”删除我手动添加的句子,但我不喜欢它,因为该网页将面向彼此认识的人。
我的两个问题:
- 有没有办法让 Django 使用我可能错过的非正式翻译?
- 如果 Django 不提供此功能,有没有办法让 Django 支持它(我很乐意提供/更改翻译)。或者您知道其他解决方案吗?
解决方案
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.
推荐阅读
- italic - 这 4 个 html 元素之间有什么区别吗?
- php - 带有键名的数组拼接
- css - 将“显示:内联块”作为“显示:网格”元素的父元素而没有文本重叠?
- css - 可变字体支持中的斜体
- python - tkinter 小部件从另一个小部件调用方法
- node.js - 使用 Lambda 和 Node.JS 的 Amazon S3 解压缩器将 content-type 设置为 application/octet-stream,并且不会提取 zip 中的最后一个文件
- java - 单击按钮时如何正确生成标签
- oracle - Oracle Sql 开发人员抛出错误消息:内部错误:获取错误消息失败!供应商代码 17001
- python - Python Selenium,为webdriver设置可执行路径使其他代码不影响webbrowser
- flutter - 在颤动中将数据持久化/存储在 GetXController 中的正确方法