Django 装置中的翻译
这是示例initial_data.json。我想让 django 将“名称”列中的值存储到翻译文件中。因此,稍后,当值在某处打印时,它可以使用其翻译后的值。有什么办法可以做到吗?谢谢。
[
{"pk": 1, "model": "category.category", "fields": {"name": "Report"}},
{"pk": 2, "model": "category.category", "fields": {"name": "Sport"}}
]
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"}}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想做类似 :: 的事情,
那么你就不走运了,因为 JSON 不支持 gettext 等。 (但是,没有什么可以阻止您在运行时将它们国际化。)如果您想做这样的事情,您需要手动将它们添加到您编写的
.po
文件中,或者将它们放在某个地方以便makemessages
可以获取它们。事实上,使用 Django 的标准机制国际化数据库值是一个非常糟糕的主意。出现问题的可能性有很多。如果国际化名称对您来说非常重要,那么您应该将国际化写入数据库模式中。 (有关更多信息,请访问 http://code.djangoproject.com/ticket/6952。 )
If you want to do something like::
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 somakemessages
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.)