Some minor changes

This commit is contained in:
Observer KRypt0n_ 2021-10-23 23:07:02 +02:00
parent 2a6c3d5780
commit 98425483fa
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
5 changed files with 20 additions and 11 deletions

View file

@ -35,6 +35,6 @@
<img src="../images/gear.png"> <img src="../images/gear.png">
</div> </div>
<button class="button" id="launch">Launch</button> <button class="button" id="launch" i18id="Launch">Launch</button>
</body> </body>
</html> </html>

View file

@ -55,7 +55,7 @@ export class LauncherUI
break; break;
case 'game-update-available': case 'game-update-available':
$('#launch').text('Update'); $('#launch').text('Update'); // FIXME i18n.translate
break; break;
@ -155,4 +155,14 @@ export class LauncherUI
{ {
Genshinlib.getBackgroundUri().then(uri => $('body').css('background-image', `url(${uri})`)); 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()!);
});
}
} }

View file

@ -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. // 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'); let samecode = new RegExp(`(${lang.replace(/-.*$/, '')}.*){2}`, 'g');
if (samecode.test(lang.toLowerCase())) if (samecode.test(lang))
lang = lang.replace(/-.*$/, ''); lang = lang.replace(/-.*$/, '');
switch (lang) switch (lang)

View file

@ -37,9 +37,7 @@ $(() => {
ipcRenderer.on('change-lang', (event: void, data: any) => { ipcRenderer.on('change-lang', (event: void, data: any) => {
LauncherUI.updateBackground(); LauncherUI.updateBackground();
LauncherUI.setState(LauncherUI.launcherState); LauncherUI.updateLang();
i18n.setLang(data.lang);
}); });
let rpc: any; let rpc: any;

View file

@ -6,6 +6,7 @@ const { exec } = require('child_process');
import $ from 'cash-dom'; import $ from 'cash-dom';
import { i18n } from './i18n'; import { i18n } from './i18n';
import { Genshinlib } from './Genshinlib'; import { Genshinlib } from './Genshinlib';
import { LauncherUI } from './LauncherUI';
$(() => { $(() => {
@ -37,13 +38,13 @@ $(() => {
$('#drpc').on('change', () => ipcRenderer.send('rpcstate', {})); $('#drpc').on('change', () => ipcRenderer.send('rpcstate', {}));
$('#voice-list').on('change', (e) => { $('#voice-list').on('change', (e) => {
let activeVP = Genshinlib.getConfig().lang.voice; let activeVP = Genshinlib.lang.voice;
if (activeVP != e.target.value) if (activeVP != e.target.value)
{ {
Genshinlib.updateConfig({ Genshinlib.updateConfig({
lang: { lang: {
launcher: Genshinlib.getConfig().lang.launcher, launcher: Genshinlib.lang.launcher,
voice: e.target.value voice: e.target.value
} }
}); });
@ -79,12 +80,12 @@ $(() => {
}); });
// Send language updates // Send language updates
i18n.setLang(e.target.value); LauncherUI.updateLang(e.target.value);
ipcRenderer.send('change-lang', { 'lang': 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()!); element.innerText = i18n.translate(element.getAttribute('i18id')?.toString()!);
}); });*/
$(`#language-list option[value="${activeLang}"]`).removeProp('selected'); $(`#language-list option[value="${activeLang}"]`).removeProp('selected');
$(`#language-list option[value="${e.target.value}"]`).prop('selected', true); $(`#language-list option[value="${e.target.value}"]`).prop('selected', true);