提交 1bc5fcaa 编写于 作者: D DCloud_LXH

feat(mp): 小程序端 getLocale 规范化

上级 13635da3
import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n'
export const getLocale: typeof uni.getLocale = () => { export const getLocale: typeof uni.getLocale = () => {
// 优先使用 $locale // 优先使用 $locale
const app = getApp({ allowDefault: true }) const app = getApp({ allowDefault: true })
if (app && app.$vm) { if (app && app.$vm) {
return app.$vm.$locale return app.$vm.$locale
} }
return __GLOBAL__.getSystemInfoSync().language || 'zh-Hans' return normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
} }
export const setLocale: typeof uni.setLocale = (locale) => { export const setLocale: typeof uni.setLocale = (locale) => {
......
...@@ -3,6 +3,7 @@ import { ComponentPublicInstance, ComponentOptions, ref } from 'vue' ...@@ -3,6 +3,7 @@ import { ComponentPublicInstance, ComponentOptions, ref } from 'vue'
import { initBaseInstance } from './componentInstance' import { initBaseInstance } from './componentInstance'
import { initHooks, initUnknownHooks } from './componentHooks' import { initHooks, initUnknownHooks } from './componentHooks'
import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n'
import App = WechatMiniprogram.App import App = WechatMiniprogram.App
import { import {
...@@ -139,7 +140,7 @@ export function initAppLifecycle( ...@@ -139,7 +140,7 @@ export function initAppLifecycle(
function initLocale(appVm: ComponentPublicInstance) { function initLocale(appVm: ComponentPublicInstance) {
const locale = ref<string>( const locale = ref<string>(
__GLOBAL__.getSystemInfoSync().language || 'zh-Hans' normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
) )
Object.defineProperty(appVm, '$locale', { Object.defineProperty(appVm, '$locale', {
get() { get() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册