summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDixsie Wolmers <dixsie@ibm.com>2020-02-26 22:22:12 +0300
committerDixsie Wolmers <dixsie@ibm.com>2020-03-06 19:10:31 +0300
commitc85395f21d7e27ba16f4b9005e7f2f2452cdd7f8 (patch)
treea93812a8cc60404120b8ae3d913afed91f1181f7
parent9fc3f90ac221bbe6b6d5b795e7fbaac68b17b7b6 (diff)
downloadwebui-vue-c85395f21d7e27ba16f4b9005e7f2f2452cdd7f8.tar.xz
Persist language settings using local storage
When user logs in, language setting will be stored in local storage. Once stored, user does not have to re-select preferred language, but can still update language settings on the login page. Before a language is saved to local storage the locale = null Renamed 'en.json' to 'en-US' because the vue i18n plugin defaults to 'en-US' when a language is not selected or null. https://github.com/kazupon/vue-i18n/blob/v8.x/src/index.js#L67 Signed-off-by: Dixsie Wolmers <dixsie@ibm.com> Change-Id: I577db3c4578eab30fbfae997dad0ece456fdf231
-rw-r--r--src/i18n.js11
-rw-r--r--src/locales/en-US.json (renamed from src/locales/en.json)0
-rw-r--r--src/views/Login/Login.vue5
3 files changed, 10 insertions, 6 deletions
diff --git a/src/i18n.js b/src/i18n.js
index 09b3f4ca..745d0504 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -21,9 +21,12 @@ function loadLocaleMessages() {
}
export default new VueI18n({
- // default language is English
- locale: 'en',
- // locale messages with a message key that doesn't exist will fallback to English
- fallbackLocale: 'en',
+ // Get default locale from local storage
+ locale: localStorage.getItem('storedLanguage'),
+ // Locales that don't exist will fallback to English
+ fallbackLocale: 'en-US',
+ // Falling back to fallbackLocale generates two console warnings
+ // Silent fallback suppresses console warnings when using fallback
+ silentFallbackWarn: true,
messages: loadLocaleMessages()
});
diff --git a/src/locales/en.json b/src/locales/en-US.json
index 0de52987..0de52987 100644
--- a/src/locales/en.json
+++ b/src/locales/en-US.json
diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue
index 10ebb930..fd6e711c 100644
--- a/src/views/Login/Login.vue
+++ b/src/views/Login/Login.vue
@@ -82,6 +82,7 @@
<script>
import { required } from 'vuelidate/lib/validators';
import VuelidateMixin from '../../components/Mixins/VuelidateMixin.js';
+import i18n from '../../i18n';
export default {
name: 'Login',
@@ -94,9 +95,8 @@ export default {
},
disableSubmitButton: false,
languages: [
- { value: null, text: this.$t('global.form.selectAnOption') },
{
- value: 'en',
+ value: 'en-US',
text: this.$t('pageLogin.form.english')
},
{
@@ -131,6 +131,7 @@ export default {
this.$store
.dispatch('authentication/login', [username, password])
.then(() => this.$router.push('/'))
+ .then(localStorage.setItem('storedLanguage', i18n.locale))
.catch(error => console.log(error))
.finally(() => (this.disableSubmitButton = false));
}