mapcomplete/UI/i18n/Locale.ts

25 lines
659 B
TypeScript
Raw Normal View History

2020-07-20 22:07:04 +00:00
import {UIEventSource} from "../UIEventSource";
import {OsmConnection} from "../../Logic/OsmConnection";
2020-07-20 10:39:43 +00:00
export default class Locale {
public static language: UIEventSource<string> = Locale.getInitialLanguage();
2020-07-20 10:39:43 +00:00
private static getInitialLanguage() {
2020-07-20 22:07:04 +00: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 10:39:43 +00:00
2020-07-20 22:07:04 +00:00
lng.addCallback(data => {
console.log("Selected language", data);
localStorage.setItem(LANGUAGE_KEY, data)
});
2020-07-20 10:39:43 +00:00
2020-07-20 22:07:04 +00:00
return lng;
2020-07-20 10:39:43 +00:00
}
}