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

feat: H5 uni.setLocale 持久化存储

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