A simple Meteor internationalization package
Simple internationalization using collections and session.
How to install
- Add the package
simple-i18n
to yoursmart.json
file. - Run
mrt
Usage
-
Run
Meteor.I18n()
on the server to publishcurrent_language_records
. -
Run
Meteor.I18n()
on the client to subscribe tocurrent_language_records
. -
Store the instance in a globally accessible i18n varialbe, and in Meteor.i18n (so it's accessible by the handlebar view helper)
i18n = Meteor.i18n = Meteor.I18n(OPTIONS_i18n);
You can pass some options to initialize the i18n package, see I18n.prototype.init
for more info
How to add translations
Do something like this (server side):
var translations = [
{lang: 'pt-br', base_str: 'Hello', new_str: 'Olá'},
{lang: 'de', base_str: 'Hello', new_str: 'Hallo'},
{lang: 'es', base_str: 'Hello', new_str: 'Hola'},
{lang: 'it', base_str: 'Hello', new_str: 'Ciao'}
];
var i18n = Meteor.I18n();
for (var i in translations) {
if (!i18n.collection.findOne({lang: translations[i].lang, base_str: translations[i].base_str})) {
i18n.insert(translations[i].lang, translations[i].base_str, translations[i].new_str);
}
}
Sample here!
http://simple-i18n-sample.meteor.com/