summaryrefslogtreecommitdiffstats
path: root/src/mixins/lang.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixins/lang.js')
-rw-r--r--src/mixins/lang.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mixins/lang.js b/src/mixins/lang.js
new file mode 100644
index 0000000..9061e7d
--- /dev/null
+++ b/src/mixins/lang.js
@@ -0,0 +1,38 @@
+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
+ * @param {string} lang Language code to switch to
+ * @returns {Promise<void>}
+ */
+ async changeLang(lang) {
+ let message = (await langModules["../lang/" + lang + ".json"]()).default;
+ this.$i18n.setLocaleMessage(lang, message);
+ this.$i18n.locale = lang;
+ localStorage.locale = lang;
+ setPageLocale();
+ }
+ }
+};