Best practice for localizing long text in Django?

Deadly 提交于 2020-01-17 05:38:24

问题


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

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?

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?


回答1:


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

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 will be of great help if you do not want to edit PO files by hand or want to delegate translations to non developers.



来源:https://stackoverflow.com/questions/32117481/best-practice-for-localizing-long-text-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!