Ghost/ghost/i18n/lib/i18n.js
Daniel Lockyer 7435b18c85
Added support for new locales
refs https://github.com/TryGhost/Team/issues/2795

- PRs for these locales were merged this morning so we need this to
  enable the languages
2023-04-10 14:05:33 +02:00

59 lines
1.1 KiB
JavaScript

const i18next = require('i18next');
const SUPPORTED_LOCALES = [
'af',
'bg',
'ca',
'cs',
'de',
'en',
'eo',
'es',
'fr',
'hu',
'it',
'mn',
'nl',
'pl',
'pt-br',
'sl',
'sv',
'tr',
'vi'
];
/**
* @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;