Add I18N system

This commit is contained in:
Maroxy 2021-10-23 01:53:33 +02:00
parent 4b1a75ce33
commit fe91ba3a94
4 changed files with 60 additions and 0 deletions

12
public/locales/de.json Normal file
View file

@ -0,0 +1,12 @@
{
"Install": "Installieren",
"Launch": "Starten",
"Runners": "Runners",
"Langs": "Sprachen",
"Voice": "Sprachpaket",
"SettingsTitle": "Einstellungen",
"GeneralSettings": "Generell",
"Downloading": "wird Heruntergeladen...",
"GameDownloaded": "Spiel würde erfolgreich heruntergeladen",
"ApplyPatch": "Patch wird angewendet"
}

12
public/locales/en-us.json Normal file
View file

@ -0,0 +1,12 @@
{
"Install": "Install",
"Launch": "Launch",
"Runners": "Runners",
"Langs": "Languages",
"Voice": "Voice Pack",
"SettingsTitle": "Settings",
"GeneralSettings": "General",
"Downloading": "Downloading...",
"GameDownloaded": "Game was successfully installed",
"ApplyPatch": "Applying patch..."
}

12
public/locales/en.json Normal file
View file

@ -0,0 +1,12 @@
{
"Install": "Install",
"Launch": "Launch",
"Runners": "Runners",
"Langs": "Languages",
"Voice": "Voice Pack",
"SettingsTitle": "Settings",
"GeneralSettings": "General",
"Downloading": "Downloading...",
"GameDownloaded": "Game was successfully installed",
"ApplyPatch": "Applying patch..."
}

24
src/ts/i18n.ts Normal file
View file

@ -0,0 +1,24 @@
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;