mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-29 04:58:16 +03:00
24 lines
742 B
TypeScript
24 lines
742 B
TypeScript
|
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
|
||
|
}
|
||
|
|
||
|
module.exports = i18n;
|