mapcomplete/UI/i18n/Locale.ts

24 lines
724 B
TypeScript
Raw Normal View History

2020-07-20 10:39:43 +00:00
import { UIEventSource } from "../UIEventSource";
2020-07-20 21:43:42 +00:00
import ParkingType from "../../Customizations/Questions/bike/ParkingType";
2020-07-20 10:39:43 +00:00
const LANGUAGE_KEY = 'language'
export default class Locale {
2020-07-20 21:43:42 +00:00
const
2020-07-20 10:39:43 +00:00
public static language: UIEventSource<string> = new UIEventSource(Locale.getInitialLanguage())
public static init() {
Locale.language.addCallback(data => {
localStorage.setItem(LANGUAGE_KEY, data)
2020-07-20 21:43:42 +00:00
if (window.confirm('In order to change the displayed language, the page needs to be reloaded. Reload now?')) {
location.reload()
}
2020-07-20 10:39:43 +00:00
})
}
private static getInitialLanguage() {
2020-07-20 21:43:42 +00:00
return localStorage.getItem(LANGUAGE_KEY) || 'en'
2020-07-20 10:39:43 +00:00
}
}