From 1bc5fcaa5fc58ad7a8aef3bdbaedfc29f6bca2cd Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 31 May 2022 16:29:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(mp):=20=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=AB=AF=20getLocale=20=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-core/src/api/locale.ts | 4 +++- packages/uni-mp-core/src/runtime/app.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/uni-mp-core/src/api/locale.ts b/packages/uni-mp-core/src/api/locale.ts index bba7bd05d..a57362216 100644 --- a/packages/uni-mp-core/src/api/locale.ts +++ b/packages/uni-mp-core/src/api/locale.ts @@ -1,10 +1,12 @@ +import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n' + export const getLocale: typeof uni.getLocale = () => { // 优先使用 $locale const app = getApp({ allowDefault: true }) if (app && app.$vm) { return app.$vm.$locale } - return __GLOBAL__.getSystemInfoSync().language || 'zh-Hans' + return normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN } export const setLocale: typeof uni.setLocale = (locale) => { diff --git a/packages/uni-mp-core/src/runtime/app.ts b/packages/uni-mp-core/src/runtime/app.ts index ef8de891d..1618c388a 100644 --- a/packages/uni-mp-core/src/runtime/app.ts +++ b/packages/uni-mp-core/src/runtime/app.ts @@ -3,6 +3,7 @@ import { ComponentPublicInstance, ComponentOptions, ref } from 'vue' import { initBaseInstance } from './componentInstance' import { initHooks, initUnknownHooks } from './componentHooks' +import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n' import App = WechatMiniprogram.App import { @@ -139,7 +140,7 @@ export function initAppLifecycle( function initLocale(appVm: ComponentPublicInstance) { const locale = ref( - __GLOBAL__.getSystemInfoSync().language || 'zh-Hans' + normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN ) Object.defineProperty(appVm, '$locale', { get() { -- GitLab