Modify language storage mode

This commit is contained in:
winbin 2021-02-15 22:51:56 +08:00
parent f51d35d101
commit d9a4fab307
3 changed files with 10 additions and 12 deletions

View File

@ -176,6 +176,7 @@ export default {
return this.$route.fullPath; return this.$route.fullPath;
}, },
...mapState({ ...mapState({
language: state => state.gui.general.language,
isConnected: state => state.socket.isConnected, isConnected: state => state.socket.isConnected,
hostname: state => state.printer.hostname, hostname: state => state.printer.hostname,
apiHost: state => state.socket.hostname, apiHost: state => state.socket.hostname,
@ -372,6 +373,9 @@ export default {
} }
}, },
watch: { watch: {
language(){
this.$i18n.locale = this.language;
},
print_percent() { print_percent() {
this.drawFavicon(this.print_percent); this.drawFavicon(this.print_percent);
}, },

View File

@ -42,18 +42,16 @@
computed: { computed: {
lang: { lang: {
get() { get() {
return localStorage.getItem("lang"); return this.$store.state.gui.general.language;
// return this.$store.state.gui.general.language;
}, },
set(language){ set(newVal){
return localStorage.setItem("lang",language); return this.$store.dispatch('gui/setSettings', { general: { language: newVal } });
// return this.$store.dispatch('gui/setSettings', { general: { language: language } });
} }
} }
}, },
methods: { methods: {
changeLanguage(val){ changeLanguage(val){
this.$i18n.locale = this.lang = val this.lang = val
} }
} }
} }

View File

@ -15,12 +15,8 @@ function loadLocaleMessages () {
return messages return messages
} }
let lang = localStorage.getItem("lang") || 'en'
localStorage.setItem("lang",lang);
export default new VueI18n({ export default new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE || lang, locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || lang, fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages() messages: loadLocaleMessages()
}) })