My question is regarding i18n in Python. From what I understand, it involves:
- Create a messages file per language (ONLY ONE?!).
- in this file, each message will be of the format
English message hereMessage en Francais ici(yea crappy french..)
- then have this file compiled into another faster binary format
- repeat for all other langs needed
- in app code (
Django) use the translate method with english (or default) language which will be translated correctly based on locale…tr('English message Here')
Probably I’m a bit off on the steps, but this seems to be the general sense right?
What I’m wondering is, is there a simpler way? I mean in the java webapp world, you set up message bundle files in the bundleName_locale.properties format. In each one you usually have a key to message relation like greeting = Hello World. You can have lots of different properties files for different sub sections of your site/app. All the locale files are hierarchical, and missing keys in a sub locale fall through to the parent etc. This is all done automatically by Java, no setup required.
Is there anything like this in the Django/Python world? Is this just insane to follow this route? Could I fake this using a module as a stand in for a java .properties file? Sorry for the long-winded question, and thanks for any input.
While you could do this fairly simply, I would question why.
As is:
gettext, which has never given me any performance problems._("My String")is normal for.pyfiles by usingfrom django.utils.translation import ugettext as _.{% trans "My String" %}in your templates. Again, quite simple.bundle.getString("My String")seems like it would get old, quick..properties-like way to define your strings, you’d still want to compile them so that you don’t have to parse the text file at execution time.Example of empty
.pofile:Personally, I don’t see a reason to bother hacking together a replacement for a solution which already exists and works well.