Ever needed to keep translations only available for the server side of Meteor? Me for sure. That's the reason why this small package exists.
Easy peasy as always 😏
meteor add jh7:server-i18n
First, initialize the package with your translation.json. You can put this file in private/i18n/translations.json
or wherever you want.
"de": {
"test": {
...
},
"hello": "Hallo %s!",
"items": "%s, dein Artikel: %s"
},
"en": {
"test": {
...
},
"hello": "Hello %s!",
"items": "%s, your item: %s"
}
import { ServerI18n } from 'meteor/jh7:server-i18n';
ServerI18n.init(Assets.getText('i18n/translations.json')); // Make sure to overload init with a string!
You can start translating now
ServerI18n.__('hello', 'en', 'Foo') // => "Hello Foo!"
ServerI18n.__('items', 'de', ['Peter', 'Ticket']) // => "Peter, dein Artikel: Ticket"
Using SSR or similar packages? Gotcha:
SSR.render('yourTemplate', {
_: ServerI18n.ssrTranslation('en'),
});
using the helper in yourTemplate
:
For the case that a language is not specified, you can specify a fallback language which will be used instead:
ServerI18n.setDefaultLang('en');
To retrieve all initialized languages:
ServerI18n.getLanguages();
Want to contribute? No problem. Just create a pull request 😄
MIT