2021-10-23 02:53:33 +03:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require('fs');
|
|
|
|
let loadedLanguage: any;
|
|
|
|
|
|
|
|
function i18n(): any {
|
|
|
|
if(fs.existsSync(path.join(path.dirname(__dirname), 'locales', navigator.language.toLowerCase() + '.json'))) {
|
|
|
|
loadedLanguage = JSON.parse(fs.readFileSync(path.join(path.dirname(__dirname), 'locales', navigator.language.toLowerCase() + '.json'), 'utf8'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loadedLanguage = JSON.parse(fs.readFileSync(path.join(path.dirname(__dirname), 'locales', 'en.json'), 'utf8'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
i18n.prototype.translate = function(phrase: any) {
|
|
|
|
let translation = loadedLanguage[phrase];
|
|
|
|
|
|
|
|
if(translation === undefined) {
|
|
|
|
translation = phrase;
|
|
|
|
}
|
|
|
|
|
|
|
|
return translation
|
|
|
|
}
|
|
|
|
|
2021-10-23 11:00:31 +03:00
|
|
|
export default new (i18n as any);
|