Any examples: i18n with Meteor/Blaze & React

I’m looking for examples of using i18n with Meteor/Blaze and Meteor/React. Will someone point me to a repo with example code?

Also, this is the lib I think I’m going to use:

1 Like

Here’s my question on the github page with examples of what I’m trying to Localize.

Config:

const i18nConfig = {
  settings: {
    defaultLocale: "en",
    ru: {
      code: "ru",
      isoCode: "ru-RU",
      name: "Русский"
    },
    en: {
      code: "en",
      isoCode: "en-US",
      name: "English"
    }
  },
  ru: {
    property: "значение",
  },
  en: {
    property: "value"
  }
};

Initialize:

import I18N from 'meteor/ostrio:i18n';
const i18n = new I18N({i18n: i18nConfig});

React:

i18n.setLocale('en');
i18n.get('property'); // -> value

i18n.setLocale('ru');
i18n.get('property'); // -> значение

You can use same in a Blaze helpers, or use TemplateHelper i18n:

<p>{{i18n 'property'}}</p> <!-- value -->
2 Likes

Thanks @dr.dimitru!

This solution works as well nicely! It’s great to know their’s still great solutions for Localizing your application in Meteor 1.8!

1 Like

Can the keys/properties be pulled from a separate file for each language? JSON or YAML for example… en.yml, es.json, fr.yml, etc?

Yes. Check out tap:i18n.

You can also dynamically load language definitions into ostrio:i18n using their addl10n function : GitHub - veliovgroup/Meteor-Internationalization: 🙊 Super-Lightweight and fast i18n isomorphic driver for Meteor with support of placeholders.

1 Like