From 54ae3bf215061ab1a59ad53da44bf361108bee17 Mon Sep 17 00:00:00 2001 From: Nolway Date: Fri, 7 Jan 2022 01:50:47 +0100 Subject: [PATCH] Add language switcher on settings --- .../Components/Menu/SettingsSubMenu.svelte | 39 ++++++++++++++++--- front/src/Translator/TranslationCompiler.ts | 32 ++++++--------- front/src/Translator/Translator.ts | 30 +++++++++++--- front/src/define-plugin.d.ts | 15 ++++++- front/translations/en-US/menu.en-US.json | 3 ++ front/translations/fr-FR/menu.fr-FR.json | 3 ++ front/webpack.config.ts | 5 +-- 7 files changed, 91 insertions(+), 36 deletions(-) diff --git a/front/src/Components/Menu/SettingsSubMenu.svelte b/front/src/Components/Menu/SettingsSubMenu.svelte index 53503902..776acbbe 100644 --- a/front/src/Components/Menu/SettingsSubMenu.svelte +++ b/front/src/Components/Menu/SettingsSubMenu.svelte @@ -4,7 +4,7 @@ import { HtmlUtils } from "../../WebRtc/HtmlUtils"; import { isMobile } from "../../Enum/EnvironmentVariable"; import { menuVisiblilityStore } from "../../Stores/MenuStore"; -import { translator } from "../../Translator/Translator"; + import { languages, translator } from "../../Translator/Translator"; let fullscreen: boolean = localUserStore.getFullscreen(); let notification: boolean = localUserStore.getNotification() === "granted"; @@ -12,14 +12,18 @@ import { translator } from "../../Translator/Translator"; let ignoreFollowRequests: boolean = localUserStore.getIgnoreFollowRequests(); let valueGame: number = localUserStore.getGameQualityValue(); let valueVideo: number = localUserStore.getVideoQualityValue(); + let valueLanguage: string = translator.getStringByLanguage(translator.getCurrentLanguage()) ?? "en-US"; let previewValueGame = valueGame; let previewValueVideo = valueVideo; + let previewValueLanguage = valueLanguage; function saveSetting() { - if (valueGame !== previewValueGame) { - previewValueGame = valueGame; - localUserStore.setGameQualityValue(valueGame); - window.location.reload(); + let change = false; + + if (valueLanguage !== previewValueLanguage) { + previewValueLanguage = valueLanguage; + translator.switchLanguage(previewValueLanguage); + change = true; } if (valueVideo !== previewValueVideo) { @@ -27,6 +31,16 @@ import { translator } from "../../Translator/Translator"; videoConstraintStore.setFrameRate(valueVideo); } + if (valueGame !== previewValueGame) { + previewValueGame = valueGame; + localUserStore.setGameQualityValue(valueGame); + change = true; + } + + if (change) { + window.location.reload(); + } + closeMenu(); } @@ -127,6 +141,17 @@ import { translator } from "../../Translator/Translator"; +
+

{translator._("menu.settings.language.title")}

+
+ +
+

{translator._("menu.settings.save.warning")}