Fix: only check browserLanguage if navigator is defined; fixes tests

This commit is contained in:
Pieter Vander Vennet 2023-06-07 00:15:04 +02:00
parent 215286a5af
commit a1fa3b4942

View file

@ -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<boolean> = new UIEventSource<boolean>(false)
@ -12,7 +12,10 @@ export default class Locale {
public static language: UIEventSource<string> = 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."