mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
6d8ca23625
refs https://github.com/TryGhost/Ghost/issues/15502 - this adds support for namespaces to the i18n package so we can separate translations for different packages
40 lines
944 B
JavaScript
40 lines
944 B
JavaScript
const i18next = require('i18next');
|
|
|
|
const SUPPORTED_LOCALES = ['en', 'nl'];
|
|
|
|
/**
|
|
* @param {string} [lng]
|
|
* @param {'portal'|'test'} ns
|
|
*/
|
|
module.exports = (lng = 'en', ns = 'portal') => {
|
|
const i18nextInstance = i18next.createInstance();
|
|
i18nextInstance.init({
|
|
lng,
|
|
debug: process.env.NODE_ENV === 'development',
|
|
|
|
// allow keys to be phrases having `:`, `.`
|
|
nsSeparator: false,
|
|
keySeparator: false,
|
|
|
|
// if the value is an empty string, return the key
|
|
returnEmptyString: false,
|
|
|
|
// do not load a fallback
|
|
fallbackLng: false,
|
|
|
|
ns: ns,
|
|
defaultNS: ns,
|
|
|
|
resources: SUPPORTED_LOCALES.reduce((acc, lng) => {
|
|
acc[lng] = {
|
|
[ns]: require(`../locales/${lng}/${ns}.json`)
|
|
}
|
|
return acc;
|
|
}, {})
|
|
});
|
|
|
|
return i18nextInstance;
|
|
};
|
|
|
|
module.exports.SUPPORTED_LOCALES = SUPPORTED_LOCALES;
|