提交 9fa1655b 编写于 作者: d-u-a's avatar d-u-a 提交者: 雪洛

feat: H5 uni.setLocale 持久化存储

上级 32559d1a
...@@ -2,3 +2,4 @@ export const NAVBAR_HEIGHT = 44 ...@@ -2,3 +2,4 @@ export const NAVBAR_HEIGHT = 44
export const TABBAR_HEIGHT = 50 export const TABBAR_HEIGHT = 50
// 576:landscape phones,768:tablets,992:desktops,1200:large desktops // 576:landscape phones,768:tablets,992:desktops,1200:large desktops
export const RESPONSIVE_MIN_WIDTH = 768 export const RESPONSIVE_MIN_WIDTH = 768
export const DC_LOCALE = '__DC_LOCALE'
...@@ -4,7 +4,11 @@ import { ...@@ -4,7 +4,11 @@ import {
} from '@dcloudio/uni-i18n' } from '@dcloudio/uni-i18n'
import { import {
isStr isStr
} from 'uni-shared' } from 'uni-shared'
import {
DC_LOCALE
} from '../constants'
import en from './en.json' import en from './en.json'
import es from './es.json' import es from './es.json'
...@@ -23,7 +27,7 @@ const messages = { ...@@ -23,7 +27,7 @@ const messages = {
let locale let locale
if (__PLATFORM__ === 'h5') { if (__PLATFORM__ === 'h5') {
locale = __uniConfig.locale || navigator.language locale = (window.localStorage && localStorage[DC_LOCALE]) || __uniConfig.locale || navigator.language
} else if (__PLATFORM__ === 'app-plus') { } else if (__PLATFORM__ === 'app-plus') {
if (typeof weex === 'object') { if (typeof weex === 'object') {
locale = weex.requireModule('plus').getLanguage() locale = weex.requireModule('plus').getLanguage()
......
...@@ -4,6 +4,9 @@ import { ...@@ -4,6 +4,9 @@ import {
import { import {
i18n i18n
} from 'uni-helpers/i18n' } from 'uni-helpers/i18n'
import {
DC_LOCALE
} from 'uni-helpers/constants'
export function getLocale () { export function getLocale () {
// 优先使用 $locale // 优先使用 $locale
...@@ -30,6 +33,9 @@ export function setLocale (locale) { ...@@ -30,6 +33,9 @@ export function setLocale (locale) {
) )
}) })
weex.requireModule('plus').setLanguage(locale) weex.requireModule('plus').setLanguage(locale)
}
if (__PLATFORM__ === 'h5') {
window.localStorage && (localStorage[DC_LOCALE] = locale)
} }
callbacks.forEach(callbackId => { callbacks.forEach(callbackId => {
invoke(callbackId, { locale }) invoke(callbackId, { locale })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册