[wip] lazy load language file

This commit is contained in:
Louis Lam
2021-11-26 16:31:19 +08:00
parent 9f0c66d775
commit 50593f3edf
4 changed files with 68 additions and 62 deletions

27
src/mixins/lang.js Normal file
View File

@@ -0,0 +1,27 @@
import { currentLocale } from "../i18n";
import { setPageLocale } from "../util-frontend";
const langModules = import.meta.glob("../languages/*.js");
export default {
data() {
return {
language: currentLocale(),
};
},
watch: {
async language(lang) {
await this.changeLang(lang);
},
},
methods: {
async changeLang(lang) {
let message = (await langModules["../languages/" + lang + ".js"]()).default;
this.$i18n.setLocaleMessage(lang, message);
this.$i18n.locale = lang;
localStorage.locale = lang;
setPageLocale();
}
}
};