uptime-kuma/src/mixins/lang.js
2023-01-15 10:46:29 +08:00

34 lines
848 B
JavaScript

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