forked from MapComplete/MapComplete
Fix: only check browserLanguage if navigator is defined; fixes tests
This commit is contained in:
parent
215286a5af
commit
a1fa3b4942
1 changed files with 10 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
import {UIEventSource} from "../../Logic/UIEventSource"
|
||||||
import { LocalStorageSource } from "../../Logic/Web/LocalStorageSource"
|
import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource"
|
||||||
import { Utils } from "../../Utils"
|
import {Utils} from "../../Utils"
|
||||||
import { QueryParameters } from "../../Logic/Web/QueryParameters"
|
import {QueryParameters} from "../../Logic/Web/QueryParameters"
|
||||||
|
|
||||||
export default class Locale {
|
export default class Locale {
|
||||||
public static showLinkToWeblate: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
public static showLinkToWeblate: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
||||||
|
@ -12,7 +12,10 @@ export default class Locale {
|
||||||
public static language: UIEventSource<string> = Locale.setup()
|
public static language: UIEventSource<string> = Locale.setup()
|
||||||
|
|
||||||
private static 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)
|
const source = LocalStorageSource.Get("language", browserLanguage)
|
||||||
if (!Utils.runningFromConsole) {
|
if (!Utils.runningFromConsole) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -20,8 +23,8 @@ export default class Locale {
|
||||||
source.setData(language)
|
source.setData(language)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(QueryParameters.wasInitialized("language")){
|
if (QueryParameters.wasInitialized("language")) {
|
||||||
const qp = QueryParameters.GetQueryParameter(
|
const qp = QueryParameters.GetQueryParameter(
|
||||||
"language",
|
"language",
|
||||||
undefined,
|
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."
|
"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."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue