Skip to content

JH7/meteor-server-i18n

Repository files navigation

Build Status

Motivation

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.

Installation

Easy peasy as always 😏

meteor add jh7:server-i18n

Usage

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:

{{_ 'items' 'Eve' 'Ticket'}} => Eve, your item: Ticket

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();

Contributing

Want to contribute? No problem. Just create a pull request 😄

License

MIT

About

I18n exclusively for the server side.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published