views:

47

answers:

1

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"}}
]
+1  A: 

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

LeafStorm