mapcomplete/UI/i18n/Locale.ts

28 lines
999 B
TypeScript
Raw Normal View History

import {UIEventSource} from "../../Logic/UIEventSource";
import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource";
2021-01-06 02:21:50 +01:00
import {Utils} from "../../Utils";
2021-08-21 20:25:36 +02:00
import {QueryParameters} from "../../Logic/Web/QueryParameters";
2020-07-20 12:39:43 +02:00
export default class Locale {
2020-07-25 18:00:08 +02:00
2020-07-31 04:58:58 +02:00
public static language: UIEventSource<string> = Locale.setup();
2020-10-27 01:01:34 +01:00
2020-07-31 04:58:58 +02:00
private static setup() {
2020-12-14 01:14:22 +01:00
const source = LocalStorageSource.Get('language', "en");
2021-01-06 02:21:50 +01:00
if (!Utils.runningFromConsole) {
2020-07-31 17:11:44 +02:00
// @ts-ignore
window.setLanguage = function (language: string) {
source.setData(language)
}
2021-08-21 20:25:36 +02:00
source.syncWith(
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."),
2021-08-21 20:25:36 +02:00
true
)
2020-07-31 04:58:58 +02:00
}
return source;
2020-07-25 18:00:08 +02:00
}
2020-07-20 12:39:43 +02:00
}
2020-07-25 18:00:08 +02:00