Hi,
I'm using that solution with Pylons and ExtJS, but i think you can easily, change JS function for your needs..
In Pylons controller i have method which exports all translations (you need polib for this - http://code.google.com/p/polib/):
import polib
from pylons.i18n import get_lang
...
## method in conttroller class
@jsonify
def get_trans(self):
def get_trans():
items = polib.mofile(os.path.join(config['pylons.paths']['root'], 'i18n/%s/LC_MESSAGES/app.mo' % get_lang()[0]))
return [{'name': item.msgid, 'value': item.msgstr} for item in items]
return {'translations' : get_trans()}
JavaScript part:
lang_store = new Ext.data.JsonStore({
url: '/lang/get',
root: 'translations',
id: 'name',
autoLoad: true,
fields: ['name', 'value'],
});
gettext = _ = function(_key) {
try {
return lang_store.getById(_key).data.value
} catch(e) {
return _key + "**"
}
}
Now you can use "gettext(STRING)" or "_(STRING)" function in JS and you'll get translated string, if there will be no translation, you'll get something like UNTRANSLATED_STRING** (with asterisks at the end) .