From 98425483fa708028845f3cb804fcf9ea94e33596 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sat, 23 Oct 2021 23:07:02 +0200 Subject: [PATCH] Some minor changes --- public/html/index.html | 2 +- src/ts/LauncherUI.ts | 12 +++++++++++- src/ts/i18n.ts | 2 +- src/ts/index.ts | 4 +--- src/ts/settings.ts | 11 ++++++----- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/public/html/index.html b/public/html/index.html index a653ee6..d530016 100644 --- a/public/html/index.html +++ b/public/html/index.html @@ -35,6 +35,6 @@ - + diff --git a/src/ts/LauncherUI.ts b/src/ts/LauncherUI.ts index 42073ee..133fa5a 100644 --- a/src/ts/LauncherUI.ts +++ b/src/ts/LauncherUI.ts @@ -55,7 +55,7 @@ export class LauncherUI break; case 'game-update-available': - $('#launch').text('Update'); + $('#launch').text('Update'); // FIXME i18n.translate break; @@ -155,4 +155,14 @@ export class LauncherUI { Genshinlib.getBackgroundUri().then(uri => $('body').css('background-image', `url(${uri})`)); } + + public static updateLang (lang: string|null = null): void + { + if (lang !== null) + i18n.setLang(lang); + + $('*[i18id]').each((i, element) => { + element.innerText = i18n.translate(element.getAttribute('i18id')?.toString()!); + }); + } } \ No newline at end of file diff --git a/src/ts/i18n.ts b/src/ts/i18n.ts index dd6f8fb..1f5fe02 100644 --- a/src/ts/i18n.ts +++ b/src/ts/i18n.ts @@ -20,7 +20,7 @@ export class i18n // Test if the locale is the same string so if it's de-de or id-id remove -de or -id like navigator.language does. let samecode = new RegExp(`(${lang.replace(/-.*$/, '')}.*){2}`, 'g'); - if (samecode.test(lang.toLowerCase())) + if (samecode.test(lang)) lang = lang.replace(/-.*$/, ''); switch (lang) diff --git a/src/ts/index.ts b/src/ts/index.ts index 6a6be6e..0438930 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -37,9 +37,7 @@ $(() => { ipcRenderer.on('change-lang', (event: void, data: any) => { LauncherUI.updateBackground(); - LauncherUI.setState(LauncherUI.launcherState); - - i18n.setLang(data.lang); + LauncherUI.updateLang(); }); let rpc: any; diff --git a/src/ts/settings.ts b/src/ts/settings.ts index 5499c68..071ad33 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -6,6 +6,7 @@ const { exec } = require('child_process'); import $ from 'cash-dom'; import { i18n } from './i18n'; import { Genshinlib } from './Genshinlib'; +import { LauncherUI } from './LauncherUI'; $(() => { @@ -37,13 +38,13 @@ $(() => { $('#drpc').on('change', () => ipcRenderer.send('rpcstate', {})); $('#voice-list').on('change', (e) => { - let activeVP = Genshinlib.getConfig().lang.voice; + let activeVP = Genshinlib.lang.voice; if (activeVP != e.target.value) { Genshinlib.updateConfig({ lang: { - launcher: Genshinlib.getConfig().lang.launcher, + launcher: Genshinlib.lang.launcher, voice: e.target.value } }); @@ -79,12 +80,12 @@ $(() => { }); // Send language updates - i18n.setLang(e.target.value); + LauncherUI.updateLang(e.target.value); ipcRenderer.send('change-lang', { 'lang': e.target.value }); - $('*[i18id]').each((i, element) => { + /*$('*[i18id]').each((i, element) => { element.innerText = i18n.translate(element.getAttribute('i18id')?.toString()!); - }); + });*/ $(`#language-list option[value="${activeLang}"]`).removeProp('selected'); $(`#language-list option[value="${e.target.value}"]`).prop('selected', true);