Django i18n:有 gettext 替代方案吗?

发布于 2024-10-09 06:59:46 字数 436 浏览 6 评论 0原文

我正在寻找一种方法来翻译我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

留一抹残留的笑 2024-10-16 06:59:46

如果您使用某些消息 ID,它们要么难以理解(“message_2215”),要么您将被迫将消息 ID 与实际消息同步(“请按任意键”=“please_press_any_key”=>“任意键继续”=“any_key_to_continue”)。不管怎样,真正的字符串对于程序员和工具来说都更好。

但是,如果您为字符串使用单独的校对器,则可以执行以下操作:

  1. 创建一个英语“翻译”文件(是的,这有效)
  2. 让您的校对器使用 Pootle 或任何其他工具将英语“翻译”为英语工具
  3. 确保您的程序员通过更新代码中的字符串来保持该翻译文件不翻译。
  4. (可选)创建一种独立于主代码部署翻译的方法,以便您可以快速修复拼写错误。

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:

  1. Create an English "translation" file (yes, this works)
  2. Let your proof-reader "translate" from English to English using Pootle or any other tool
  3. Make sure your programmers keep that translation file untranslated by updating the strings in code.
  4. (optional) Create a way to deploy translations independently of your main code so you can fix a typo quickly.
没企图 2024-10-16 06:59:46

您也许可以通过 _("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).

寻找一个思念的角度 2024-10-16 06:59:46

使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文