From c643d8e1194b4ef317b2814945915cd438a57b5d Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 26 Aug 2021 16:57:56 +0800 Subject: [PATCH] fix: Language -> Locale --- lib/apis.js | 4 ++-- .../lib/platforms/app-plus/index.js | 2 +- .../webpack-uni-pages-loader/lib/platforms/h5.js | 6 +++--- src/core/helpers/i18n/index.js | 10 +++++----- src/core/helpers/promise.js | 2 +- src/core/service/api/ui/language.js | 12 ------------ src/core/service/api/ui/locale.js | 4 ++++ 7 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 src/core/service/api/ui/language.js create mode 100644 src/core/service/api/ui/locale.js diff --git a/lib/apis.js b/lib/apis.js index 357a7a7294..3eb34ba698 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -183,8 +183,8 @@ const ui = [ 'setTopWindowStyle', 'setLeftWindowStyle', 'setRightWindowStyle', - 'getLanguage', - 'setLanguage' + 'getLocale', + 'setLocale' ] const event = [ diff --git a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js index 3d0cd24888..f2b94f93b6 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js @@ -128,7 +128,7 @@ module.exports = function (pagesJson, userManifestJson, isAppView) { name: userManifestJson.versionName, code: userManifestJson.versionCode }, - language: userManifestJson.language + language: userManifestJson.locale }, { plus: userManifestJson['app-plus'] } diff --git a/packages/webpack-uni-pages-loader/lib/platforms/h5.js b/packages/webpack-uni-pages-loader/lib/platforms/h5.js index 46302deb2f..23c7c3ba92 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/h5.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/h5.js @@ -438,8 +438,8 @@ module.exports = function (pagesJson, manifestJson, loader) { qqMapKey = sdkConfigs.maps.qqmap.key } - let language = manifestJson.language - language = language && language.toUpperCase() !== 'AUTO' ? language : '' + let locale = manifestJson.locale + locale = locale && locale.toUpperCase() !== 'AUTO' ? locale : '' return ` import Vue from 'vue' @@ -455,7 +455,7 @@ global.__uniConfig.debug = ${manifestJson.debug === true}; global.__uniConfig.networkTimeout = ${JSON.stringify(networkTimeoutConfig)}; global.__uniConfig.sdkConfigs = ${JSON.stringify(sdkConfigs)}; global.__uniConfig.qqMapKey = ${JSON.stringify(qqMapKey)}; -global.__uniConfig.language = ${JSON.stringify(language)}; +global.__uniConfig.locale = ${JSON.stringify(locale)}; global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(manifestJson['app-plus']) })} global.__uniConfig.__webpack_chunk_load__ = __webpack_chunk_load__ ${genRegisterPageVueComponentsCode(pageComponents)} diff --git a/src/core/helpers/i18n/index.js b/src/core/helpers/i18n/index.js index bedfbc8819..000490cac0 100644 --- a/src/core/helpers/i18n/index.js +++ b/src/core/helpers/i18n/index.js @@ -16,19 +16,19 @@ const messages = { 'zh-Hant': zhHant } -let language +let locale if (__PLATFORM__ === 'h5') { - language = (__uniConfig.language || navigator.language) + locale = (__uniConfig.locale || navigator.language) } else if (__PLATFORM__ === 'app-plus') { if (typeof weex === 'object') { - language = weex.requireModule('plus').getLanguage() + locale = weex.requireModule('plus').getLanguage() } } else { - language = uni.getSystemInfoSync().language + locale = uni.getSystemInfoSync().language } -export const i18n = initVueI18n(language, __PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {}) +export const i18n = initVueI18n(locale, __PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {}) export const t = i18n.t export const i18nMixin = i18n.mixin = { beforeCreate () { diff --git a/src/core/helpers/promise.js b/src/core/helpers/promise.js index 3be095c656..b76a07be46 100644 --- a/src/core/helpers/promise.js +++ b/src/core/helpers/promise.js @@ -8,7 +8,7 @@ import { } from './interceptor' const SYNC_API_RE = - /^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLanguage|setLanguage/ + /^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/ const CONTEXT_API_RE = /^create|Manager$/ diff --git a/src/core/service/api/ui/language.js b/src/core/service/api/ui/language.js deleted file mode 100644 index 4c578b5505..0000000000 --- a/src/core/service/api/ui/language.js +++ /dev/null @@ -1,12 +0,0 @@ -import { - getLocale, - setLocale -} from 'uni-core/helpers/i18n' - -export function getLanguage () { - return getLocale() -} - -export function setLanguage (locale) { - return setLocale(locale) -} diff --git a/src/core/service/api/ui/locale.js b/src/core/service/api/ui/locale.js new file mode 100644 index 0000000000..37bf3cb506 --- /dev/null +++ b/src/core/service/api/ui/locale.js @@ -0,0 +1,4 @@ +export { + getLocale, + setLocale +} from 'uni-core/helpers/i18n' -- GitLab