From 6fb9fc4e6f104fe4fe4850323aeecc9d6c487efa Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 25 Mar 2020 13:55:25 +0000 Subject: [PATCH] move loadLanguage to init.ts Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/app.js | 23 +---------------------- src/vector/init.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/vector/app.js b/src/vector/app.js index 8bf73531..6099b3aa 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -27,7 +27,6 @@ import ReactDOM from 'react-dom'; import * as sdk from 'matrix-react-sdk'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import * as VectorConferenceHandler from 'matrix-react-sdk/src/VectorConferenceHandler'; -import * as languageHandler from 'matrix-react-sdk/src/languageHandler'; import {_t, _td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler'; import AutoDiscoveryUtils from 'matrix-react-sdk/src/utils/AutoDiscoveryUtils'; import {AutoDiscovery} from "matrix-js-sdk/src/autodiscovery"; @@ -38,13 +37,12 @@ import url from 'url'; import {parseQs, parseQsFromFragment} from './url_utils'; import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg'; -import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore"; import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import {setTheme} from "matrix-react-sdk/src/theme"; import CallHandler from 'matrix-react-sdk/src/CallHandler'; import {loadConfig, preparePlatform} from "./initial-load"; -import {loadOlm} from "./init"; +import {loadLanguage, loadOlm} from "./init"; let lastLocationHashSet = null; @@ -305,25 +303,6 @@ export async function loadApp() { } } -async function loadLanguage() { - const prefLang = SettingsStore.getValue("language", null, /*excludeDefault=*/true); - let langs = []; - - if (!prefLang) { - languageHandler.getLanguagesFromBrowser().forEach((l) => { - langs.push(...languageHandler.getNormalizedLanguageKeys(l)); - }); - } else { - langs = [prefLang]; - } - try { - await languageHandler.setLanguage(langs); - document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage()); - } catch (e) { - console.error("Unable to set language", e); - } -} - async function verifyServerConfig() { let validatedConfig; try { diff --git a/src/vector/init.ts b/src/vector/init.ts index a51987b1..96fd57b0 100644 --- a/src/vector/init.ts +++ b/src/vector/init.ts @@ -22,6 +22,10 @@ limitations under the License. import olmWasmPath from "olm/olm.wasm"; import Olm from 'olm'; +import * as languageHandler from 'matrix-react-sdk/src/languageHandler'; +import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore"; + + export function loadOlm() { /* Load Olm. We try the WebAssembly version first, and then the legacy, * asm.js version if that fails. For this reason we need to wait for this @@ -58,3 +62,22 @@ export function loadOlm() { }); }); } + +export async function loadLanguage() { + const prefLang = SettingsStore.getValue("language", null, /*excludeDefault=*/true); + let langs = []; + + if (!prefLang) { + languageHandler.getLanguagesFromBrowser().forEach((l) => { + langs.push(...languageHandler.getNormalizedLanguageKeys(l)); + }); + } else { + langs = [prefLang]; + } + try { + await languageHandler.setLanguage(langs); + document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage()); + } catch (e) { + console.error("Unable to set language", e); + } +}