mapcomplete/UI/i18n/Locale.ts

25 lines
659 B
TypeScript
Raw Normal View History

2020-07-21 00:07:04 +02:00
import {UIEventSource} from "../UIEventSource";
import {OsmConnection} from "../../Logic/OsmConnection";
2020-07-20 12:39:43 +02:00
export default class Locale {
public static language: UIEventSource<string> = Locale.getInitialLanguage();
2020-07-20 12:39:43 +02:00
private static getInitialLanguage() {
2020-07-21 00:07:04 +02:00
// The key to save in local storage
const LANGUAGE_KEY = 'language'
const lng = new UIEventSource("en");
const saved = localStorage.getItem(LANGUAGE_KEY);
lng.setData(saved);
2020-07-20 12:39:43 +02:00
2020-07-21 00:07:04 +02:00
lng.addCallback(data => {
console.log("Selected language", data);
localStorage.setItem(LANGUAGE_KEY, data)
});
2020-07-20 12:39:43 +02:00
2020-07-21 00:07:04 +02:00
return lng;
2020-07-20 12:39:43 +02:00
}
}