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
diff --git a/src/i18n.js b/src/i18n.js
index 09b3f4c..745d050 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -21,9 +21,12 @@
}
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()
});