diff --git a/packages/uni-mp-core/src/api/locale.ts b/packages/uni-mp-core/src/api/locale.ts index bba7bd05d4853c81fb0322e57950d6462327b11e..a57362216376f2180dae142ccfcdcc9b37871111 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 ef8de891db93ea8e18df098bd2a0ea419d24d7dc..1618c388a436c3ef753b78538d93f2a8b3312ef5 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() {