uptime-kuma/src/mixins/lang.js

35 lines
854 B
JavaScript
Raw Normal View History

2021-11-26 08:31:19 +00:00
import { currentLocale } from "../i18n";
import { setPageLocale } from "../util-frontend";
const langModules = import.meta.glob("../languages/*.js");
export default {
data() {
return {
language: currentLocale(),
};
},
async created() {
if (this.language !== "en") {
await this.changeLang(this.language);
}
},
2021-11-26 08:31:19 +00:00
watch: {
async language(lang) {
await this.changeLang(lang);
},
},
methods: {
/** Change the application language */
2021-11-26 08:31:19 +00:00
async changeLang(lang) {
let message = (await langModules["../languages/" + lang + ".js"]()).default;
this.$i18n.setLocaleMessage(lang, message);
this.$i18n.locale = lang;
localStorage.locale = lang;
setPageLocale();
}
}
};