提交 a5e78997 编写于 作者: Q qiang

Merge branch 'dev' into alpha

# Conflicts:
#	packages/uni-mp-weixin/dist/index.js
......@@ -16,15 +16,21 @@ import fr from './fr.json'
import zhHans from './zh-Hans.json'
import zhHant from './zh-Hant.json'
export const LOCALE_ZH_HANS = 'zh-Hans'
export const LOCALE_ZH_HANT = 'zh-Hant'
export const LOCALE_EN = 'en'
export const LOCALE_FR = 'fr'
export const LOCALE_ES = 'es'
const messages = {}
if (__PLATFORM__ === 'h5' || __PLATFORM__ === 'app-plus') {
Object.assign(messages, {
en,
es,
fr,
'zh-Hans': zhHans,
'zh-Hant': zhHant
[LOCALE_EN]: en,
[LOCALE_ES]: es,
[LOCALE_FR]: fr,
[LOCALE_ZH_HANS]: zhHans,
[LOCALE_ZH_HANT]: zhHant
})
}
......@@ -39,7 +45,7 @@ if (__PLATFORM__ === 'h5') {
locale = ''
}
} else {
locale = __GLOBAL__.getSystemInfoSync().language
locale = normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
}
function initI18nMessages () {
......@@ -95,7 +101,7 @@ export function initAppLocale (Vue, appVm, locale) {
}
Object.defineProperty(appVm, '$locale', {
get () {
return state.locale
return normalizeLocale(state.locale)
},
set (v) {
state.locale = v
......@@ -110,7 +116,7 @@ function getLocaleMessage () {
const locale = uni.getLocale()
const locales = __uniConfig.locales
return (
locales[locale] || locales[__uniConfig.fallbackLocale] || locales.en || {}
locales[locale] || locales[__uniConfig.fallbackLocale] || locales[LOCALE_EN] || {}
)
}
......@@ -190,6 +196,44 @@ export function initTabBarI18n (tabBar) {
return tabBar
}
function include (str, parts) {
return !!parts.find((part) => str.indexOf(part) !== -1)
}
function startsWith (str, parts) {
return parts.find((part) => str.indexOf(part) === 0)
}
export function normalizeLocale (locale, messages) {
if (!locale) {
return
}
locale = locale.trim().replace(/_/g, '-')
if (messages && messages[locale]) {
return locale
}
locale = locale.toLowerCase()
if (locale === 'chinese') {
// 支付宝
return LOCALE_ZH_HANS
}
if (locale.indexOf('zh') === 0) {
if (locale.indexOf('-hans') > -1) {
return LOCALE_ZH_HANS
}
if (locale.indexOf('-hant') > -1) {
return LOCALE_ZH_HANT
}
if (include(locale, ['-tw', '-hk', '-mo', '-cht'])) {
return LOCALE_ZH_HANT
}
return LOCALE_ZH_HANS
}
const lang = startsWith(locale, [LOCALE_EN, LOCALE_FR, LOCALE_ES])
if (lang) {
return lang
}
}
// export function initI18n() {
// const localeKeys = Object.keys(__uniConfig.locales || {})
// if (localeKeys.length) {
......@@ -197,4 +241,4 @@ export function initTabBarI18n (tabBar) {
// i18n.add(locale, __uniConfig.locales[locale])
// )
// }
// }
// }
import { normalizeLocale, LOCALE_EN } from '../helpers/i18n/index'
export function getLocale () {
// 优先使用 $locale
const app = getApp({
......@@ -6,7 +8,7 @@ export function getLocale () {
if (app && app.$vm) {
return app.$vm.$locale
}
return __GLOBAL__.getSystemInfoSync().language || 'zh-Hans'
return normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
}
export function setLocale (locale) {
......@@ -34,4 +36,4 @@ export function onLocaleChange (fn) {
if (typeof global !== 'undefined') {
global.getLocale = getLocale
}
}
......@@ -171,7 +171,7 @@ export function getBrowserInfo () {
var system = `${osname} ${osversion}`
var platform = osname.toLocaleLowerCase()
let browserName
let browserName = ''
let browseVersion = String(IEVersion())
if (browseVersion !== '-1') { browserName = 'IE' } else {
const browseVendors = ['Version', 'Firefox', 'Chrome', 'Edge{0,1}']
......
......@@ -66,7 +66,8 @@ export function populateParameters (result) {
const deviceBrand = getDeviceBrand(brand, model, isQuickApp)
// hostName
let _hostName = hostName || __PLATFORM__.split('-')[1] // mp-jd
const _platform = __PLATFORM__ === 'mp-weixin' ? 'WeChat' : __PLATFORM__.split('-')[1]
let _hostName = hostName || _platform // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (environment) {
_hostName = environment
......
......@@ -6,7 +6,9 @@ import {
} from 'uni-wrapper/util'
import {
initAppLocale
initAppLocale,
normalizeLocale,
LOCALE_EN
} from 'uni-helpers/i18n/index'
import EventChannel from 'uni-helpers/EventChannel'
......@@ -185,7 +187,7 @@ export default function parseBaseApp (vm, {
})
}
initAppLocale(Vue, vm, __GLOBAL__.getSystemInfoSync().language || 'zh-Hans')
initAppLocale(Vue, vm, normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN)
initHooks(appOptions, hooks)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册