Ghost/ghost/i18n/lib/i18n.js
Daniel Lockyer bed7479cc2 Fixed loading pt-br translations
fixes https://github.com/TryGhost/Ghost/issues/16805

* turns out i18next requires the country portal of the locale to be
  capitalized [1]
* this resolves that and moves the files to the correct casing

[1]: https://github.com/i18next/i18next/issues/1467#issuecomment-646305827
2023-05-24 10:27:49 +02:00

68 lines
1.2 KiB
JavaScript

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