2021-11-26 08:31:19 +00:00
|
|
|
import { currentLocale } from "../i18n";
|
|
|
|
import { setPageLocale } from "../util-frontend";
|
2022-12-27 10:11:53 +00:00
|
|
|
const langModules = import.meta.glob("../lang/*.json");
|
2021-11-26 08:31:19 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
language: currentLocale(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-11-29 08:45:52 +00:00
|
|
|
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: {
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Change the application language
|
|
|
|
* @param {string} lang Language code to switch to
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2021-11-26 08:31:19 +00:00
|
|
|
async changeLang(lang) {
|
2022-12-27 10:11:53 +00:00
|
|
|
let message = (await langModules["../lang/" + lang + ".json"]()).default;
|
2021-11-26 08:31:19 +00:00
|
|
|
this.$i18n.setLocaleMessage(lang, message);
|
|
|
|
this.$i18n.locale = lang;
|
|
|
|
localStorage.locale = lang;
|
|
|
|
setPageLocale();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|