2018-07-06 03:17:38 +00:00
|
|
|
/**
|
|
|
|
* Languages Loader
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
|
2019-03-06 14:28:50 +00:00
|
|
|
const merge = (...args) => args.reduce((a, c) => ({
|
|
|
|
...a,
|
|
|
|
...c,
|
2022-07-10 09:15:11 +00:00
|
|
|
// this is necessary to merge "sub-objects" correctly instead of overwriting them
|
2019-03-06 14:28:50 +00:00
|
|
|
...Object.entries(a)
|
|
|
|
.filter(([k]) => c && typeof c[k] === 'object')
|
|
|
|
.reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {})
|
|
|
|
}), {});
|
2018-07-06 03:17:38 +00:00
|
|
|
|
2022-07-10 09:15:11 +00:00
|
|
|
// For a language to be generated as a locale it has to be listed here.
|
2019-03-06 14:28:50 +00:00
|
|
|
const languages = [
|
2020-05-29 23:00:02 +00:00
|
|
|
'ar-SA',
|
2022-07-13 09:43:13 +00:00
|
|
|
'bn-BD',
|
|
|
|
'ca-ES',
|
2020-11-07 03:32:08 +00:00
|
|
|
'cs-CZ',
|
2020-04-11 09:30:39 +00:00
|
|
|
'de-DE',
|
2019-03-06 14:28:50 +00:00
|
|
|
'en-US',
|
|
|
|
'es-ES',
|
2020-02-12 13:40:35 +00:00
|
|
|
'fr-FR',
|
2021-05-23 09:57:33 +00:00
|
|
|
'id-ID',
|
2021-10-31 14:18:55 +00:00
|
|
|
'it-IT',
|
2019-03-06 14:28:50 +00:00
|
|
|
'ja-JP',
|
2020-02-12 13:40:35 +00:00
|
|
|
'ja-KS',
|
2020-11-07 03:32:08 +00:00
|
|
|
'kab-KAB',
|
|
|
|
'kn-IN',
|
2019-03-06 14:28:50 +00:00
|
|
|
'ko-KR',
|
2020-11-07 03:32:08 +00:00
|
|
|
'nl-NL',
|
|
|
|
'pl-PL',
|
|
|
|
'pt-PT',
|
|
|
|
'ru-RU',
|
2022-02-20 15:16:40 +00:00
|
|
|
'sk-SK',
|
2022-07-13 09:43:13 +00:00
|
|
|
'sv-SE',
|
|
|
|
'tr-TR',
|
2020-11-07 03:32:08 +00:00
|
|
|
'uk-UA',
|
2022-07-13 10:24:53 +00:00
|
|
|
'vi-VN',
|
2020-02-10 11:29:44 +00:00
|
|
|
'zh-CN',
|
2020-04-11 09:30:39 +00:00
|
|
|
'zh-TW',
|
2019-03-06 14:28:50 +00:00
|
|
|
];
|
|
|
|
|
2022-07-10 09:15:11 +00:00
|
|
|
// Load the locales listed above.
|
|
|
|
const locales = languages.reduce(
|
|
|
|
(acc, lang) => {
|
|
|
|
acc[lang] = yaml.load(
|
|
|
|
fs.readFileSync(`${__dirname}/${lang}.yml`, 'utf-8')
|
|
|
|
// Remove backspace characters, which for some reason can get mixed in with the string and break the YAML.
|
|
|
|
.replaceAll('\b', '')
|
|
|
|
) || {};
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{} // initial accumulator
|
|
|
|
);
|
2019-03-06 14:28:50 +00:00
|
|
|
|
|
|
|
module.exports = Object.entries(locales)
|
2022-07-10 09:15:11 +00:00
|
|
|
.reduce((acc, [lang, strings]) => {
|
2022-07-13 09:43:13 +00:00
|
|
|
if (lang == 'en-US') {
|
2022-07-10 09:15:11 +00:00
|
|
|
acc[lang] = strings;
|
|
|
|
} else {
|
|
|
|
// all other locales fall back to en-US
|
|
|
|
acc[lang] = merge(locales['en-US'], strings);
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{} // initial accumulator
|
|
|
|
);
|