eb5ed7dda8
refs https://github.com/TryGhost/Team/issues/2795 - this helps reduce conflicts when multiple PRs are coming in to add new languages - I'd also like to enforce alphabetically sorted keys but I can't figure out the magic eslint incantation yet
42 lines
917 B
JavaScript
42 lines
917 B
JavaScript
const i18next = require('i18next');
|
|
|
|
const SUPPORTED_LOCALES = [
|
|
'en',
|
|
'nl'
|
|
];
|
|
|
|
/**
|
|
* @param {string} [lng]
|
|
* @param {'ghost'|'portal'|'test'} ns
|
|
*/
|
|
module.exports = (lng = 'en', ns = 'portal') => {
|
|
const i18nextInstance = i18next.createInstance();
|
|
i18nextInstance.init({
|
|
lng,
|
|
|
|
// 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, locale) => {
|
|
acc[locale] = {
|
|
[ns]: require(`../locales/${locale}/${ns}.json`)
|
|
};
|
|
return acc;
|
|
}, {})
|
|
});
|
|
|
|
return i18nextInstance;
|
|
};
|
|
|
|
module.exports.SUPPORTED_LOCALES = SUPPORTED_LOCALES;
|