开发者

translation in django fixtures

Here is example initial_data.json. I want开发者_运维技巧 let django store value from column 'name' into translation file. So later, when value is printed somewhere, it could use its translated value. Is there any way to do it? Thanks.

[
{"pk": 1, "model": "category.category", "fields": {"name": "Report"}},
{"pk": 2, "model": "category.category", "fields": {"name": "Sport"}}
]


If you want to do something like::

"fields": {"name": _("Report")}

Then you're out of luck, as JSON has no support for gettext and the like. (There's nothing preventing you from internationalizing them at runtime, however.) If you want to do something like this, you would need to either manually add them to the .po files you write, or put them somewhere in the code so makemessages can pick them up.

Though really, internationalizing database values with Django's standard mechanisms is a Really Bad Idea. There's all sorts of potential for things to go wrong. If internationalizing the names is that important to you, you should write the internationalization into your database schema. (More information on that at http://code.djangoproject.com/ticket/6952.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜