2023-01-18 15:21:17 +03:00
|
|
|
const i18next = require('i18next');
|
|
|
|
|
2023-03-22 10:50:29 +03:00
|
|
|
const SUPPORTED_LOCALES = [
|
2023-05-30 16:31:09 +03:00
|
|
|
'af', // Afrikaans
|
|
|
|
'bg', // Bulgarian
|
|
|
|
'ca', // Catalan
|
|
|
|
'cs', // Czech
|
|
|
|
'da', // Danish
|
|
|
|
'de', // German
|
|
|
|
'en', // English
|
|
|
|
'eo', // Esperanto
|
|
|
|
'es', // Spanish
|
|
|
|
'fi', // Finnish
|
|
|
|
'fr', // French
|
2023-11-20 18:56:51 +03:00
|
|
|
'gd', // Gaelic (Scottish)
|
2023-06-14 13:27:40 +03:00
|
|
|
'hr', // Croatian
|
2023-05-30 16:31:09 +03:00
|
|
|
'hu', // Hungarian
|
|
|
|
'id', // Indonesian
|
2023-08-29 10:38:04 +03:00
|
|
|
'is', // Icelandic
|
2023-05-30 16:31:09 +03:00
|
|
|
'it', // Italian
|
2023-08-16 12:44:01 +03:00
|
|
|
'ja', // Japanese
|
2023-08-29 10:38:41 +03:00
|
|
|
'ko', // Korean
|
2023-05-30 16:31:09 +03:00
|
|
|
'mn', // Mongolian
|
2023-06-14 13:27:40 +03:00
|
|
|
'ms', // Malay
|
2023-05-30 16:31:09 +03:00
|
|
|
'nl', // Dutch
|
2023-07-20 09:47:27 +03:00
|
|
|
'nn', // Norwegian Nynorsk
|
2023-08-29 10:38:41 +03:00
|
|
|
'no', // Norwegian
|
2023-05-30 16:31:09 +03:00
|
|
|
'pl', // Polish
|
|
|
|
'pt', // Portuguese
|
|
|
|
'pt-BR', // Portuguese (Brazil)
|
|
|
|
'ro', // Romanian
|
|
|
|
'ru', // Russian
|
|
|
|
'si', // Sinhala
|
2023-10-31 16:23:18 +03:00
|
|
|
'sk', // Slovak
|
2023-05-30 16:31:09 +03:00
|
|
|
'sl', // Slovenian
|
|
|
|
'sq', // Albanian
|
|
|
|
'sr', // Serbian
|
|
|
|
'sv', // Swedish
|
|
|
|
'tr', // Turkish
|
|
|
|
'uk', // Ukrainian
|
|
|
|
'uz', // Uzbek
|
|
|
|
'vi', // Vietnamese
|
2023-05-31 10:52:42 +03:00
|
|
|
'zh', // Chinese
|
|
|
|
'zh-Hant' // Traditional Chinese
|
2023-03-22 10:50:29 +03:00
|
|
|
];
|
2023-01-18 20:21:36 +03:00
|
|
|
|
2023-03-01 11:10:11 +03:00
|
|
|
/**
|
|
|
|
* @param {string} [lng]
|
2023-08-23 14:52:57 +03:00
|
|
|
* @param {'ghost'|'portal'|'test'|'signup-form'|'comments'} ns
|
2023-03-01 11:10:11 +03:00
|
|
|
*/
|
|
|
|
module.exports = (lng = 'en', ns = 'portal') => {
|
2023-01-18 15:21:17 +03:00
|
|
|
const i18nextInstance = i18next.createInstance();
|
|
|
|
i18nextInstance.init({
|
|
|
|
lng,
|
|
|
|
|
|
|
|
// allow keys to be phrases having `:`, `.`
|
|
|
|
nsSeparator: false,
|
|
|
|
keySeparator: false,
|
|
|
|
|
2023-02-27 15:17:27 +03:00
|
|
|
// if the value is an empty string, return the key
|
|
|
|
returnEmptyString: false,
|
|
|
|
|
2023-01-18 15:21:17 +03:00
|
|
|
// do not load a fallback
|
|
|
|
fallbackLng: false,
|
|
|
|
|
2023-03-01 11:10:11 +03:00
|
|
|
ns: ns,
|
|
|
|
defaultNS: ns,
|
|
|
|
|
2023-03-01 12:30:18 +03:00
|
|
|
resources: SUPPORTED_LOCALES.reduce((acc, locale) => {
|
2023-08-23 14:52:57 +03:00
|
|
|
const res = require(`../locales/${locale}/${ns}.json`);
|
|
|
|
|
|
|
|
// Note: due some random thing in TypeScript, 'requiring' a JSON file with a space in a key name, only adds it to the default export
|
|
|
|
// If changing this behaviour, please also check the comments and signup-form apps in another language (mainly sentences with a space in them)
|
2023-03-01 12:30:18 +03:00
|
|
|
acc[locale] = {
|
2023-08-23 14:52:57 +03:00
|
|
|
[ns]: {...res, ...(res.default && typeof res.default === 'object' ? res.default : {})}
|
2023-03-01 12:30:18 +03:00
|
|
|
};
|
2023-03-01 11:10:11 +03:00
|
|
|
return acc;
|
|
|
|
}, {})
|
2023-01-18 15:21:17 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return i18nextInstance;
|
|
|
|
};
|
2023-01-18 20:21:36 +03:00
|
|
|
|
|
|
|
module.exports.SUPPORTED_LOCALES = SUPPORTED_LOCALES;
|