本文介绍了在Django中本地化长文本的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读完有关国际化的Django文档,发现有些问题困扰着我.

I just got done reading the Django docs on internationalization and something is bugging me.

似乎默认语言字符串本身也用作检索翻译的键.对于短文本来说这是完全可以的,但是对于段落来说,这似乎是糟糕的设计.现在,每当我更改英语(默认)文本时,我的密钥都会更改,我需要手动更新我的.po文件吗?

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?

使用正确的方法似乎是使用"INTRO_TEXT"之类的键并从其自己的.po文件中检索默认语言.别人如何解决这个问题,什么对您有效?

It seems like using keys like "INTRO_TEXT" and retrieving the default language from it's own .po file is the right approach. How have others approached this problem and what has worked well for you?

推荐答案

是的,您将必须手动更新PO文件,但是在大多数情况下,删除过时翻译中的模糊标记将受到限制. ( gettext 在修改原始版本时将翻译标记为模糊).

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).

我个人更喜欢这种方法,因为它可以将文本内容保留在源代码中,从而使其更具可读性(尤其是对于HTML).我还发现很难找到简洁明了的字符串标识符,名称不正确的标识符容易引起头痛.

I personally prefer this approach as it keeps the text content in the source code which makes it much more readable (especially for HTML). I also find it hard to find good and concise string identifiers, poorly named identifiers are headache prone.

Django-rosetta 将会有很大的帮助还是希望将翻译委托给非开发人员.

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.

这篇关于在Django中本地化长文本的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 00:30