OSDN Git Service

store language setting in localstorage
authorYongfeng LI <wliyongfeng@gmail.com>
Thu, 8 Feb 2018 06:11:16 +0000 (14:11 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Thu, 8 Feb 2018 08:10:35 +0000 (16:10 +0800)
src/features/core/reducers.js

index 14a06c9..4a20b47 100644 (file)
@@ -206,8 +206,10 @@ const snapshot = (state = null, action) => {
 
 const version = (state, action) => coreConfigReducer('version', state, 'N/A', action)
 
-const lang = (state = window.navigator.language.startsWith('zh') ? 'zh' : 'en', action) => {
+const defaultLang = window.localStorage.getItem('language') || (window.navigator.language.startsWith('zh') ? 'zh' : 'en')
+const lang = (state = defaultLang, action) => {
   if (action.type === 'UPDATE_CORE_LANGUAGE') {
+    window.localStorage.setItem('language', action.lang || '')
     return action.lang || ''
   }
   return state