From a1fa3b494259d7cc8f4873af31d5c9a987cef972 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 7 Jun 2023 00:15:04 +0200 Subject: [PATCH] Fix: only check browserLanguage if navigator is defined; fixes tests --- UI/i18n/Locale.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/UI/i18n/Locale.ts b/UI/i18n/Locale.ts index 2c405c980..94638507d 100644 --- a/UI/i18n/Locale.ts +++ b/UI/i18n/Locale.ts @@ -1,7 +1,7 @@ -import { UIEventSource } from "../../Logic/UIEventSource" -import { LocalStorageSource } from "../../Logic/Web/LocalStorageSource" -import { Utils } from "../../Utils" -import { QueryParameters } from "../../Logic/Web/QueryParameters" +import {UIEventSource} from "../../Logic/UIEventSource" +import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource" +import {Utils} from "../../Utils" +import {QueryParameters} from "../../Logic/Web/QueryParameters" export default class Locale { public static showLinkToWeblate: UIEventSource = new UIEventSource(false) @@ -12,7 +12,10 @@ export default class Locale { public static language: UIEventSource = Locale.setup() private static setup() { - const browserLanguage =navigator.languages?.[0] ?? navigator.language ?? "en" + let browserLanguage = "en" + if (typeof navigator !== "undefined") { + browserLanguage = navigator.languages?.[0] ?? navigator.language ?? "en" + } const source = LocalStorageSource.Get("language", browserLanguage) if (!Utils.runningFromConsole) { // @ts-ignore @@ -20,8 +23,8 @@ export default class Locale { source.setData(language) } } - if(QueryParameters.wasInitialized("language")){ - const qp = QueryParameters.GetQueryParameter( + if (QueryParameters.wasInitialized("language")) { + const qp = QueryParameters.GetQueryParameter( "language", undefined, "The language to display mapcomplete in. Will be ignored in case a logged-in-user did set their language before. If the specified language does not exist, it will default to the first language in the theme."