2017-03-04 16:15:16 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
2018-11-17 22:26:45 +00:00
|
|
|
const i18n = require("i18next");
|
2018-11-18 20:31:22 +00:00
|
|
|
const fs = require('fs');
|
2017-03-04 16:15:16 +00:00
|
|
|
const path = require('path');
|
2018-11-18 20:31:22 +00:00
|
|
|
const {convertToFake, langCodes} = require('../../shared/langs');
|
|
|
|
|
|
|
|
const resourcesCommon = {};
|
|
|
|
|
|
|
|
function loadLanguage(shortCode) {
|
|
|
|
resourcesCommon[shortCode] = {
|
|
|
|
common: JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'locales', shortCode, 'common.json')))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
loadLanguage('en');
|
|
|
|
loadLanguage('es');
|
|
|
|
resourcesCommon.fake = convertToFake(resourcesCommon.en);
|
|
|
|
|
|
|
|
const resources = {};
|
|
|
|
for (const lng of config.enabledLanguages) {
|
|
|
|
const shortCode = langCodes[lng].shortCode;
|
|
|
|
resources[shortCode] = {
|
|
|
|
common: resourcesCommon[shortCode]
|
|
|
|
};
|
|
|
|
}
|
2017-03-04 16:15:16 +00:00
|
|
|
|
2018-11-17 22:26:45 +00:00
|
|
|
i18n
|
|
|
|
.init({
|
2018-11-18 20:31:22 +00:00
|
|
|
resources,
|
2018-11-17 22:26:45 +00:00
|
|
|
wait: true, // globally set to wait for loaded translations in translate hoc
|
|
|
|
|
2018-11-18 20:31:22 +00:00
|
|
|
fallbackLng: config.defaultLanguage,
|
2018-11-17 22:26:45 +00:00
|
|
|
defaultNS: 'common',
|
|
|
|
|
2018-11-18 20:31:22 +00:00
|
|
|
debug: false
|
2018-11-17 22:26:45 +00:00
|
|
|
})
|
|
|
|
|
2018-11-18 20:31:22 +00:00
|
|
|
|
|
|
|
|
2018-11-17 22:26:45 +00:00
|
|
|
function tLog(key, args) {
|
|
|
|
if (!args) {
|
|
|
|
args = {};
|
2017-03-04 16:15:16 +00:00
|
|
|
}
|
2017-03-07 14:30:56 +00:00
|
|
|
|
2018-11-17 22:26:45 +00:00
|
|
|
return JSON.stringify([key, args]);
|
|
|
|
}
|
|
|
|
|
2018-11-18 14:38:52 +00:00
|
|
|
function tUI(key, lang, args) {
|
2018-11-17 22:26:45 +00:00
|
|
|
if (!args) {
|
|
|
|
args = {};
|
2017-03-07 14:30:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-17 22:26:45 +00:00
|
|
|
return i18n.t(key, { ...args, defaultValue, lng: lang });
|
|
|
|
}
|
|
|
|
|
2018-11-18 14:38:52 +00:00
|
|
|
function tMark(key) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2018-11-17 22:26:45 +00:00
|
|
|
module.exports.tLog = tLog;
|
2018-11-18 14:38:52 +00:00
|
|
|
module.exports.tUI = tUI;
|
|
|
|
module.exports.tMark = tMark;
|