Skip to content

Introduce a child process - namespaced instance

Compare
Choose a tag to compare
@omrilotan omrilotan released this 18 Sep 05:38
· 46 commits to master since this release

Scoped child instance

This is a good option for shorthand in enclosed parts of the application.

The translation store is shared so the parent can find the keys if it prefixes the namespace, and the child doesn't need to.

The child can also find "global" translations (ones that are outside it's namespace)

const usersI18n = i18n.spawn('users.get');

// Add translations under the scope
usersI18n.add({introduction: 'Hi, my name is %{username}'});

// Use translations
usersI18n.t('introduction', {username: 'Martin'}); // Hi, my name is Martin
i18n.t('users.get.introduction', {username: 'Martin'}); // Hi, my name is Martin