diff --git a/src/core/helpers/constants.js b/src/core/helpers/constants.js index bec72ef81d99c576f41015c1879e7fee822a12e5..24a14dc03b7eda5f95c8aa9a472edc716912c96a 100644 --- a/src/core/helpers/constants.js +++ b/src/core/helpers/constants.js @@ -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' diff --git a/src/core/helpers/i18n/index.js b/src/core/helpers/i18n/index.js index 778fbc2c21eb903dfbbf54579c5dcfe2d99c0f9d..3112531480d0a99522f22e461fcdeeb5860b083a 100644 --- a/src/core/helpers/i18n/index.js +++ b/src/core/helpers/i18n/index.js @@ -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() diff --git a/src/core/service/api/ui/locale.js b/src/core/service/api/ui/locale.js index 0713493b02a83bddb6e7732c5d686642267e244d..6d360290acf7d9f1972f7d137d56936186d77567 100644 --- a/src/core/service/api/ui/locale.js +++ b/src/core/service/api/ui/locale.js @@ -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 })