Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');
i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
if (err) {
console.log('something went wrong loading', err)
return
}
t('key') // -> same as i18next.t
})
i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
i18next.loadNamespaces(
['myNamespace1', 'myNamespace2'],
(err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
},
)
i18next.loadLanguages('de', (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
i18next.loadLanguages(['de', 'fr'], (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
// reload all
i18next.reloadResources()
updateContent()
},
)
i18next.init(
{
ns: ['common', 'moduleA', 'moduleB'],
defaultNS: 'moduleA',
},
(err: any, t: i18next.TranslationFunction) => {
i18next.t('myKey') // key in moduleA namespace (defined default)
i18next.t('common:myKey') // key in common namespace
},
)
i18next.loadNamespaces('anotherNamespace', (err: any, t: i18next.TranslationFunction) => {
/* ... */
})
// fallback to one language
i18next.init(
{
lng: 'en-GB',
},
() => {
i18next.t('i18n') // -> "Internationalisation"
i18next.t('i18n_short') // -> "i18n" (from en.json)
// force loading en
i18next.t('i18n', { lng: 'en' }) // -> "Internationalization"
},
)
const de = i18next.getFixedT('de')
const z: string = de('myKey')
// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');
i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
if (err) {
console.log('something went wrong loading', err)
return
}
t('key') // -> same as i18next.t
})
i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
i18next.loadNamespaces(
['myNamespace1', 'myNamespace2'],
(err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
},
)
i18next.loadLanguages('de', (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
i18next.loadLanguages(['de', 'fr'], (err: any, t: i18next.TranslationFunction) => {
/* resources have been loaded */
})
fs.readdir(dir,function(err, files) {
if (err) {
resolve();
} else {
files.forEach(function(f) {
if (fs.existsSync(path.join(dir,f,file))) {
resourceMap[namespace].lngs.push(f);
}
});
i18n.loadNamespaces(namespace,function() {
resolve();
});
}
})
});
const translate = () => {
if (i18next.exists(namespacedKey, options)) {
subscriber.next(i18next.t(namespacedKey, options));
} else {
if (whitespaceUntilLoaded) {
subscriber.next(this.NON_BREAKING_SPACE);
}
i18next.loadNamespaces(chunkName, () => {
if (!i18next.exists(namespacedKey, options)) {
this.reportMissingKey(key, chunkName);
subscriber.next(this.getFallbackValue(namespacedKey));
} else {
subscriber.next(i18next.t(namespacedKey, options));
}
});
}
};
const loadLocales = () => {
i18next.addResourceBundle('en', 'modulesDocs', {
metadata: {
name: 'modulesDocs',
displayName: 'Modules Docs Module',
description: 'This module shows the very basic usage of Bractal, and it simply does only one job, which is loading and showing all home pages of all the loaded modules',
},
home: {
menuTitle: 'Modules Docs',
},
}, true, true);
i18next.loadNamespaces('modulesDocs');
};
loadChunks(chunkNames: string | string[]): Promise {
return i18next.loadNamespaces(chunkNames);
}
return fn => {
i18next.loadNamespaces(ns)
return
}
}
function changeNamespace(ns) {
if (!ns && lastOptions.namespaceFromPath) ns = getPathname();
lastOptions.ns.push(ns);
lastOptions.defaultNS = ns;
i18next.loadNamespaces(lastOptions.ns, () => {
i18next.setDefaultNamespace(ns);
});
}