简体   繁体   English

在Django中本地化长文本的最佳实践?

[英]Best practice for localizing long text in Django?

I just got done reading the Django docs on internationalization and something is bugging me. 我刚阅读完有关国际化的Django文档,就发现有些问题困扰着我。

It seems like the default language strings are themselves used as the keys for retrieving translations. 似乎默认语言字符串本身也用作检索翻译的键。 That's perfectly fine for short text, but for paragraphs, it seems like poor design. 对于短文本来说,这是完全可以的,但是对于段落来说,这似乎是糟糕的设计。 Now, whenever I change the English (default) text, my keys change and I need to manually update my .po file? 现在,每当我更改英语(默认)文本时,我的密钥都会更改,我需要手动更新.po文件吗?

It seems like using keys like "INTRO_TEXT" and retrieving the default language from it's own .po file is the right approach. 似乎使用“ INTRO_TEXT”之类的键并从其自己的.po文件中检索默认语言是正确的方法。 How have others approached this problem and what has worked well for you? 别人如何解决这个问题,什么对您有效?

Yes, you will have to manually update the PO files, but most of the times it will be limited to remove the fuzzy marks on out-of-date translations ( gettext marks translations as fuzzy when the original version is modified). 是的,您将必须手动更新PO文件,但是在大多数情况下,删除过时翻译上的模糊标记(在修改原始版本时, gettext标记翻译为模糊)受到限制。

I personally prefer this approach as it keeps the text content in the source code which makes it much more readable (especially for HTML). 我个人更喜欢这种方法,因为它可以将文本内容保留在源代码中,从而使其更具可读性(尤其是对于HTML)。 I also find it hard to find good and concise string identifiers, poorly named identifiers are headache prone. 我还发现很难找到简洁明了的字符串标识符,名称不正确的标识符容易引起头痛。

Django-rosetta will be of great help if you do not want to edit PO files by hand or want to delegate translations to non developers. 如果您不想手动编辑PO文件或希望将翻译委托给非开发人员,则Django-rosetta会提供很大的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM