Skip to main content
Version: 5.x.x

Namespaces

Tolgee namespaces are a way how to separate translations into multiple files, which can be downloaded only when needed. By default Tolgee uses "" (empty string) namespace. You can change this through initial Options.

const tolgee = Tolgee().init({
// set default namespace
defaultNs: 'common',

// define which namespaces should be fetched initially
ns: ['common', 'test'],
});

Definition through staticData

You can tell Tolgee how to get namespaces through staticData, ideally with async function:

const tolgee = Tolgee().init({
staticData: {
'en:common': () => import('./i18n/common/en.json'),
'en:test': () => import('./i18n/test/en.json'),
},
});

You can also use plugins for loading namespaces check Providing static data.

Active namespaces

To download new namespaces dynamically you can change active namespaces with addActiveNs method. Active namespaces are automatically fetched and also when you change the languge (when tolgee is running).

tolgee.addActiveNs('newNamespace');

Removing active namespace:

tolgee.removeActiveNs('newNamespace');

Tolgee internally rembers how many times is each namespace used and removed, so it will only remove namespace if removeActiveNs was called the same time as addActiveNs.