2023-01-15 11:08:38 +01:00
|
|
|
// intentionally disabled because I don't know the quality of the languages, so better to default to english
|
2021-03-28 19:12:58 +02:00
|
|
|
// const LanguageDetector = window.require('i18next-electron-language-detector');
|
|
|
|
const isDev = require('electron-is-dev');
|
|
|
|
const { app } = require('electron');
|
|
|
|
const { join } = require('path');
|
|
|
|
|
2023-02-17 05:56:36 +01:00
|
|
|
const { frontendBuildDir } = require('./util');
|
|
|
|
|
2023-03-10 06:30:41 +01:00
|
|
|
let customLocalesPath;
|
|
|
|
function setCustomLocalesPath(p) {
|
|
|
|
customLocalesPath = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLangPath(subPath) {
|
|
|
|
if (customLocalesPath != null) return join(customLocalesPath, subPath);
|
|
|
|
if (isDev) return join('public', subPath);
|
|
|
|
return join(app.getAppPath(), frontendBuildDir, subPath);
|
|
|
|
}
|
2021-03-28 19:12:58 +02:00
|
|
|
|
|
|
|
// Weblate hardcodes different lang codes than electron
|
2021-07-23 17:26:21 +02:00
|
|
|
// https://www.electronjs.org/docs/api/app#appgetlocale
|
|
|
|
// https://source.chromium.org/chromium/chromium/src/+/master:ui/base/l10n/l10n_util.cc
|
2021-03-28 19:12:58 +02:00
|
|
|
const mapLang = (lng) => ({
|
|
|
|
nb: 'nb_NO',
|
|
|
|
no: 'nb_NO',
|
|
|
|
zh: 'zh_Hans',
|
2021-07-23 17:26:15 +02:00
|
|
|
// https://source.chromium.org/chromium/chromium/src/+/master:ui/base/l10n/l10n_util.cc;l=354
|
|
|
|
'zh-CN': 'zh_Hans', // Chinese simplified (mainland China)
|
|
|
|
'zh-TW': 'zh_Hant', // Chinese traditional (Taiwan)
|
2021-03-28 19:12:58 +02:00
|
|
|
fr: 'fr',
|
|
|
|
'fr-CA': 'fr',
|
|
|
|
'fr-CH': 'fr',
|
|
|
|
'fr-FR': 'fr',
|
|
|
|
it: 'it',
|
|
|
|
'it-CH': 'it',
|
|
|
|
'it-IT': 'it',
|
|
|
|
'ru-RU': 'ru',
|
|
|
|
}[lng] || lng);
|
|
|
|
|
|
|
|
const fallbackLng = 'en';
|
|
|
|
|
|
|
|
const commonI18nOptions = {
|
|
|
|
fallbackLng,
|
|
|
|
// debug: isDev,
|
|
|
|
// saveMissing: isDev,
|
|
|
|
// updateMissing: isDev,
|
|
|
|
// saveMissingTo: 'all',
|
|
|
|
|
2023-02-18 16:16:02 +01:00
|
|
|
// Keep in sync between i18next-parser.config.js and i18n-common.js:
|
2021-03-28 19:12:58 +02:00
|
|
|
// TODO improve keys?
|
|
|
|
// Maybe do something like this: https://stackoverflow.com/a/19405314/6519037
|
|
|
|
keySeparator: false,
|
|
|
|
nsSeparator: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const loadPath = (lng, ns) => getLangPath(`locales/${mapLang(lng)}/${ns}.json`);
|
|
|
|
const addPath = (lng, ns) => getLangPath(`locales/${mapLang(lng)}/${ns}.missing.json`);
|
|
|
|
|
2023-03-10 06:30:41 +01:00
|
|
|
module.exports = {
|
|
|
|
fallbackLng,
|
|
|
|
loadPath,
|
|
|
|
addPath,
|
|
|
|
commonI18nOptions,
|
|
|
|
setCustomLocalesPath,
|
|
|
|
};
|