Django i18n:有 gettext 替代方案吗?
我正在寻找一种方法来翻译我的 Django 项目。 Django 提供的内置机制很棒,但有几个弱点,这让我开始寻找替代方案。
项目所有者必须能够编辑每个翻译,包括英文(原始翻译)。借助 gettext,可以使用 Pootle 等工具编辑翻译,但原始字符串仍硬编码在文件源或模板内。产品负责人无法更改它们。
可能的解决方案是让 gettext 翻译一些唯一标识符,然后将它们翻译成包括英语在内的所有语言,如下所示:
_('form_sumbit_button')
但这使得像 pootle 这样的工具几乎无法被翻译人员使用。
问题:有没有可以满足我需求的 Django 项目翻译工具?
I'm looking for a way to translate my Django project. Built in mechanism provided with Django is great, but has several weak points which made me go looking for an alternative.
Project owner must be able to edit every translation including English (original translation). With gettext it is possible to edit translations with tools like Pootle, but the original strings stay hardcoded inside file sources or templates. There is no way that product owner can change them.
Possible solution is to make gettext translate some unique identifiers, and just translate them to all languages including English, like this:
_('form_sumbit_button')
But this makes tools like pootle almost impossible to use for translators.
Question: are there any tools for Django project translation that could fit my needs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用某些消息 ID,它们要么难以理解(“message_2215”),要么您将被迫将消息 ID 与实际消息同步(“请按任意键”=“please_press_any_key”=>“任意键继续”=“any_key_to_continue”)。不管怎样,真正的字符串对于程序员和工具来说都更好。
但是,如果您为字符串使用单独的校对器,则可以执行以下操作:
If you use some message IDs, they would either be incomprehensible ("message_2215") or you'd be forced to synchronise the message IDs to the actual messages ("Please press any key" = "please_press_any_key" => "Any key to continue" = "any_key_to_continue"). Either way, real strings are better for the programmers and for the tools.
However, if you employ a separate proof-reader for your strings, you can do the following:
您也许可以通过 _("message_id") 方法使用 Pootle,具体取决于 Pootle 的自定义难度(我不知道内部原理,所以我不能说,但 IIUC 它使用 Django,其中模板更改通常是直截了当)。
例如,Pootle 的翻译屏幕有“原文”和“翻译”部分;您也许可以调整模板以在“原始”部分下显示“参考”部分,该部分使用特定参考语言(例如英语)显示一些规范翻译。
或者您也可以使用 Pootle 的替代源语言功能,无需定制 Pootle。您可以使用未使用的语言代码(或虚构的语言代码)来存储翻译的规范版本。
You may be able to use Pootle with the _("message_id") approach, depending on how easy Pootle is to customise (I don't know the internals so I can't say, but IIUC it uses Django where template changes are usually straightforward).
For example, Pootle's translation screens have "Original" and "Translation" sections; you could perhaps adapt the templates to show, under the "Original" section, a "Reference" section which displays some canonical translation using a specific reference language (e.g. English).
Or you may be able to use Pootle's alternative source language functionality, without needing to customise Pootle. You could store the canonical versions of the translations using an unused language code (or a made-up one).
使用 Gettext 绝对可以使用标识符,并且有支持此功能的工具。然而,对于某些翻译人员来说,这可能不常见,因为他们习惯于仅下载 .po 文件进行离线翻译,这不适用于单语翻译。
例如 Weblate 就可以很好地支持单语 Gettext 文件(我是这个工具的作者): https://docs.weblate.org/en/latest/formats.html#monolingual-gettext
Using identifiers is definitely possible with Gettext and there are tools which support this. However it might be unusual for some translators as they are used to downloading only .po file for offline translation, what does not work with monolingual translations.
For example Weblate supports monolingual Gettext files just fine (I'm author of this tool): https://docs.weblate.org/en/latest/formats.html#monolingual-gettext