From d5eda2ca4438f6c3d311a3b25123fdddc5405ab0 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 14 Apr 2021 15:42:05 +0800 Subject: [PATCH] refactor: make i18n tree-shakeable --- dist/static/logo.png | Bin 4023 -> 0 bytes packages/global.d.ts | 5 + packages/uni-api/src/helpers/api/index.ts | 18 +- packages/uni-api/src/index.ts | 1 + .../src/protocols/network/downloadFile.ts | 2 +- .../uni-api/src/protocols/network/request.ts | 26 +- .../src/protocols/network/uploadFile.ts | 8 +- packages/uni-api/src/protocols/ui/popup.js | 117 --- packages/uni-api/src/protocols/ui/popup.ts | 104 +++ packages/uni-api/src/type.ts | 2 +- .../src/components/button/index.tsx | 6 +- packages/uni-core/src/helpers/i18n/index.ts | 26 - packages/uni-core/src/helpers/index.ts | 1 - .../uni-core/src/{helpers => }/i18n/en.json | 0 .../uni-core/src/{helpers => }/i18n/es.json | 0 .../uni-core/src/{helpers => }/i18n/fr.json | 0 packages/uni-core/src/i18n/index.ts | 2 + packages/uni-core/src/i18n/messages.ts | 634 +++++++++++++ packages/uni-core/src/i18n/useI18n.ts | 6 + .../src/{helpers => }/i18n/zh-Hans.json | 0 .../src/{helpers => }/i18n/zh-Hant.json | 0 packages/uni-core/src/index.ts | 1 + packages/uni-h5-vue/dist/vue.runtime.esm.js | 3 +- packages/uni-h5-vue/lib/vue.runtime.esm.js | 3 +- packages/uni-h5/dist/uni-h5.esm.js | 870 +++++++++--------- .../components/async-error/index.vue | 5 +- packages/uni-h5/src/service/api/index.ts | 1 + packages/uni-h5/src/service/api/ui/popup.ts | 56 ++ packages/uni-i18n/dist/uni-i18n.cjs.js | 48 +- packages/uni-i18n/dist/uni-i18n.d.ts | 25 +- packages/uni-i18n/dist/uni-i18n.esm.js | 45 +- packages/uni-i18n/src/I18n.ts | 33 +- packages/uni-i18n/src/vue-i18n.ts | 24 +- packages/uni-mp-alipay/dist/uni.api.esm.js | 13 +- packages/uni-mp-baidu/dist/uni.api.esm.js | 13 +- packages/uni-mp-qq/dist/uni.api.esm.js | 13 +- packages/uni-mp-toutiao/dist/uni.api.esm.js | 13 +- packages/uni-mp-weixin/dist/uni.api.esm.js | 13 +- .../uni-quickapp-webview/dist/uni.api.esm.js | 13 +- packages/vite-plugin-uni/src/utils/define.ts | 44 +- scripts/i18n.js | 90 ++ scripts/utils.js | 4 +- yarn.lock | 12 +- 43 files changed, 1563 insertions(+), 737 deletions(-) delete mode 100644 dist/static/logo.png delete mode 100644 packages/uni-api/src/protocols/ui/popup.js create mode 100644 packages/uni-api/src/protocols/ui/popup.ts delete mode 100644 packages/uni-core/src/helpers/i18n/index.ts rename packages/uni-core/src/{helpers => }/i18n/en.json (100%) rename packages/uni-core/src/{helpers => }/i18n/es.json (100%) rename packages/uni-core/src/{helpers => }/i18n/fr.json (100%) create mode 100644 packages/uni-core/src/i18n/index.ts create mode 100644 packages/uni-core/src/i18n/messages.ts create mode 100644 packages/uni-core/src/i18n/useI18n.ts rename packages/uni-core/src/{helpers => }/i18n/zh-Hans.json (100%) rename packages/uni-core/src/{helpers => }/i18n/zh-Hant.json (100%) create mode 100644 packages/uni-h5/src/service/api/ui/popup.ts create mode 100644 scripts/i18n.js diff --git a/dist/static/logo.png b/dist/static/logo.png deleted file mode 100644 index b5771e209bb677e2ebd5ff766ad5ee11790f305a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4023 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 SYs}WS&%*SCNx89m_( } const formatArgs = options.formatArgs! Object.keys(formatArgs).forEach((name) => { - formatArgs[name]!(args[0][name], params) + const formatterOrDefaultValue = formatArgs[name]! + if (isFunction(formatterOrDefaultValue)) { + formatterOrDefaultValue(args[0][name], params) + } else { + // defaultValue + if (!hasOwn(params, name)) { + params[name] = formatterOrDefaultValue + } + } }) return args } diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index d0dd7a82b..443d6c9b8 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -31,6 +31,7 @@ export * from './protocols/network/uploadFile' export * from './protocols/route/route' export * from './protocols/ui/navigationBar' +export * from './protocols/ui/popup' export * from './protocols/ui/tabBar' // helpers export { diff --git a/packages/uni-api/src/protocols/network/downloadFile.ts b/packages/uni-api/src/protocols/network/downloadFile.ts index 97820ae38..bad7d2740 100644 --- a/packages/uni-api/src/protocols/network/downloadFile.ts +++ b/packages/uni-api/src/protocols/network/downloadFile.ts @@ -2,7 +2,7 @@ export const API_DOWNLOAD_FILE = 'downloadFile' export type API_TYPE_DOWNLOAD_FILE = typeof uni.downloadFile export const DownloadFileOptions: ApiOptions = { formatArgs: { - header(value, params) { + header(value: Record, params: Record) { params.header = value || {} }, }, diff --git a/packages/uni-api/src/protocols/network/request.ts b/packages/uni-api/src/protocols/network/request.ts index 7c42bc612..6f33c5df5 100644 --- a/packages/uni-api/src/protocols/network/request.ts +++ b/packages/uni-api/src/protocols/network/request.ts @@ -43,28 +43,16 @@ function stringifyQuery(url: string, data: Record) { } export const RequestProtocol: ApiProtocol = { - method: { - type: String as any, - }, - data: { - type: [Object, String, Array, ArrayBuffer], - }, + method: String as any, + data: [Object, String, Array, ArrayBuffer], url: { type: String, required: true, }, - header: { - type: Object, - }, - dataType: { - type: String, - }, - responseType: { - type: String, - }, - withCredentials: { - type: Boolean, - }, + header: Object, + dataType: String, + responseType: String, + withCredentials: Boolean, } export const RequestOptions: ApiOptions = { @@ -88,7 +76,7 @@ export const RequestOptions: ApiOptions = { params.url = stringifyQuery(value, params.data) } }, - header(value, params) { + header(value: Record, params: Record) { const header = (params.header = value || {}) if (params.method !== HTTP_METHODS[0]) { if ( diff --git a/packages/uni-api/src/protocols/network/uploadFile.ts b/packages/uni-api/src/protocols/network/uploadFile.ts index ab2e6bcda..89d8d1b5e 100644 --- a/packages/uni-api/src/protocols/network/uploadFile.ts +++ b/packages/uni-api/src/protocols/network/uploadFile.ts @@ -2,10 +2,10 @@ export const API_UPLOAD_FILE = 'uploadFile' export type API_TYPE_UPLOAD_FILE = typeof uni.uploadFile export const UploadFileOptions: ApiOptions = { formatArgs: { - header(value, params) { + header(value: Record, params: Record) { params.header = value || {} }, - formData(value, params) { + formData(value: Record, params: Record) { params.formData = value || {} }, }, @@ -16,9 +16,7 @@ export const UploadFileProtocol: ApiProtocol = { type: String, required: true, }, - files: { - type: Array, - }, + files: Array, filePath: String, name: String, header: Object, diff --git a/packages/uni-api/src/protocols/ui/popup.js b/packages/uni-api/src/protocols/ui/popup.js deleted file mode 100644 index 3fcca2630..000000000 --- a/packages/uni-api/src/protocols/ui/popup.js +++ /dev/null @@ -1,117 +0,0 @@ -import getRealPath from 'uni-platform/helpers/get-real-path' - -export const showModal = { - title: { - type: String, - default: '' - }, - content: { - type: String, - default: '' - }, - showCancel: { - type: Boolean, - default: true - }, - cancelText: { - type: String, - default: '取消' - }, - cancelColor: { - type: String, - default: '#000000' - }, - confirmText: { - type: String, - default: '确定' - }, - confirmColor: { - type: String, - default: '#007aff' - }, - visible: { - type: Boolean, - default: true - } -} - -export const showToast = { - title: { - type: String, - default: '' - }, - icon: { - default: 'success', - validator(icon, params) { - if (['success', 'loading', 'none'].indexOf(icon) === -1) { - params.icon = 'success' - } - } - }, - image: { - type: String, - default: '', - validator(image, params) { - if (image) { - params.image = getRealPath(image) - } - } - }, - duration: { - type: Number, - default: 1500 - }, - mask: { - type: Boolean, - default: false - }, - visible: { - type: Boolean, - default: true - } -} -export const showLoading = { - title: { - type: String, - default: '' - }, - icon: { - type: String, - default: 'loading' - }, - duration: { - type: Number, - default: 100000000 // 简单处理 showLoading,直接设置个大值 - }, - mask: { - type: Boolean, - default: false - }, - visible: { - type: Boolean, - default: true - } -} - -export const showActionSheet = { - itemList: { - type: Array, - required: true, - validator(itemList, params) { - if (!itemList.length) { - return 'parameter.itemList should have at least 1 item' - } - } - }, - itemColor: { - type: String, - default: '#000000' - }, - visible: { - type: Boolean, - default: true - }, - popover: { - type: Object - } -} diff --git a/packages/uni-api/src/protocols/ui/popup.ts b/packages/uni-api/src/protocols/ui/popup.ts new file mode 100644 index 000000000..e74604027 --- /dev/null +++ b/packages/uni-api/src/protocols/ui/popup.ts @@ -0,0 +1,104 @@ +import { hasOwn } from '@vue/shared' +import { useI18n, initI18nShowModalMsgs } from '@dcloudio/uni-core' +import { PRIMARY_COLOR } from '@dcloudio//uni-shared' +import { getRealPath } from '@dcloudio/uni-platform' +export const API_SHOW_MODAL = 'showModal' +export type API_TYPE_SHOW_MODAL = typeof uni.showModal + +const { t } = useI18n() + +export const ShowModalProtocol: ApiProtocol = { + title: String, + content: String, + showCancel: Boolean, + cancelText: String, + cancelColor: String, + confirmText: String, + confirmColor: String, +} +let isInitI18nShowModalMsgs = false +export const ShowModalOptions: ApiOptions = { + beforeInvoke() { + // dynamic init (tree shaking) + if (isInitI18nShowModalMsgs) { + return + } + isInitI18nShowModalMsgs = true + initI18nShowModalMsgs() + }, + formatArgs: { + title: '', + content: '', + showCancel: true, + cancelText(_value, params) { + if (!hasOwn(params, 'cancelText')) { + params.cancelText = t('uni.showModal.cancel') + } + }, + cancelColor: '#000', + confirmText(_value, params) { + if (!hasOwn(params, 'confirmText')) { + params.confirmText = t('uni.showModal.confirm') + } + }, + confirmColor: PRIMARY_COLOR, + }, +} +export const API_SHOW_TOAST = 'showToast' +export type API_TYPE_SHOW_TOAST = typeof uni.showToast +export const ShowToastProtocol: ApiProtocol = { + title: String, + icon: String as any, + image: String, + duration: Number, + mask: Boolean, +} +export const ShowToastOptions: ApiOptions = { + formatArgs: { + title: '', + icon(value, params) { + if (['success', 'loading', 'none'].indexOf(value!) === -1) { + params.icon = 'success' + } + }, + image(value, params) { + if (value) { + params.image = getRealPath(value) + } + }, + duration: 1500, + mask: false, + }, +} +export const API_SHOW_LOADING = 'showLoading' +export type API_TYPE_SHOW_LOADING = typeof uni.showLoading +export const ShowLoadingProtocol: ApiProtocol = { + title: String, + mask: Boolean, +} +export const ShowLoadingOptions: ApiOptions = { + formatArgs: { + title: '', + mask: false, + }, +} + +export const API_SHOW_ACTION_SHEET = 'showActionSheet' +export type API_TYPE_SHOW_ACTION_SHEET = typeof uni.showActionSheet +export const ShowActionSheetProtocol: ApiProtocol = { + itemList: { + type: Array, + required: true, + }, + itemColor: String, +} +export const ShowActionSheetOptions: ApiOptions = { + formatArgs: { + itemColor: '#000', + }, +} + +export const API_HIDE_TOAST = 'hideToast' +export type API_TYPE_HIDE_TOAST = typeof uni.hideToast +export const API_HIDE_LOADING = 'hideLoading' +export type API_TYPE_HIDE_LOADING = typeof uni.hideLoading diff --git a/packages/uni-api/src/type.ts b/packages/uni-api/src/type.ts index af31f3cd4..2744a6670 100644 --- a/packages/uni-api/src/type.ts +++ b/packages/uni-api/src/type.ts @@ -22,7 +22,7 @@ interface ApiOptions> { beforeAll?: (res: unknown) => void beforeSuccess?: (res: unknown) => void formatArgs?: { - [K in keyof P]?: ApiArgsValidator + [K in keyof P]?: ApiArgsValidator | P[K] } } diff --git a/packages/uni-components/src/components/button/index.tsx b/packages/uni-components/src/components/button/index.tsx index 433a26473..26a3afc85 100644 --- a/packages/uni-components/src/components/button/index.tsx +++ b/packages/uni-components/src/components/button/index.tsx @@ -1,9 +1,13 @@ import { defineComponent, inject } from 'vue' -import { useI18n } from '@dcloudio/uni-core' +import { useI18n, initI18nButtonMsgs } from '@dcloudio/uni-core' import { useHover } from '../../helpers/useHover' import { useBooleanAttr } from '../../helpers/useBooleanAttr' import { UniFormCtx, uniFormKey } from '../form' +if (__PLATFORM__ === 'app-plus') { + initI18nButtonMsgs() +} + export default defineComponent({ name: 'Button', props: { diff --git a/packages/uni-core/src/helpers/i18n/index.ts b/packages/uni-core/src/helpers/i18n/index.ts deleted file mode 100644 index 12cb581e5..000000000 --- a/packages/uni-core/src/helpers/i18n/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { initVueI18n } from '@dcloudio/uni-i18n' - -import en from './en.json' -import es from './es.json' -import fr from './fr.json' -import zhHans from './zh-Hans.json' -import zhHant from './zh-Hant.json' - -const messages = { - en, - es, - fr, - 'zh-Hans': zhHans, - 'zh-Hant': zhHant, -} - -const fallbackLocale = 'en' - -const i18n = /*#__PURE__*/ initVueI18n( - __PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {}, - fallbackLocale -) - -export function useI18n() { - return i18n -} diff --git a/packages/uni-core/src/helpers/index.ts b/packages/uni-core/src/helpers/index.ts index 5516b9994..44af56a36 100644 --- a/packages/uni-core/src/helpers/index.ts +++ b/packages/uni-core/src/helpers/index.ts @@ -1,5 +1,4 @@ export * from './util' export * from './icon' -export * from './i18n' export * from './getRealRoute' export * from './getWindowOffset' diff --git a/packages/uni-core/src/helpers/i18n/en.json b/packages/uni-core/src/i18n/en.json similarity index 100% rename from packages/uni-core/src/helpers/i18n/en.json rename to packages/uni-core/src/i18n/en.json diff --git a/packages/uni-core/src/helpers/i18n/es.json b/packages/uni-core/src/i18n/es.json similarity index 100% rename from packages/uni-core/src/helpers/i18n/es.json rename to packages/uni-core/src/i18n/es.json diff --git a/packages/uni-core/src/helpers/i18n/fr.json b/packages/uni-core/src/i18n/fr.json similarity index 100% rename from packages/uni-core/src/helpers/i18n/fr.json rename to packages/uni-core/src/i18n/fr.json diff --git a/packages/uni-core/src/i18n/index.ts b/packages/uni-core/src/i18n/index.ts new file mode 100644 index 000000000..d9fe75110 --- /dev/null +++ b/packages/uni-core/src/i18n/index.ts @@ -0,0 +1,2 @@ +export * from './useI18n' +export * from './messages' diff --git a/packages/uni-core/src/i18n/messages.ts b/packages/uni-core/src/i18n/messages.ts new file mode 100644 index 000000000..8598ea137 --- /dev/null +++ b/packages/uni-core/src/i18n/messages.ts @@ -0,0 +1,634 @@ +// This file is created by scripts/i18n.js +// Do not modify this file!!!!!!!!! +import { + LOCALE_EN, + LOCALE_ES, + LOCALE_FR, + LOCALE_ZH_HANS, + LOCALE_ZH_HANT, +} from '@dcloudio/uni-i18n' +import { useI18n } from './useI18n' +const i18n = useI18n() +function normalizeMessages( + namespace: string, + messages: Record +) { + return Object.keys(messages).reduce>((res, name) => { + res[namespace + name] = messages[name] + return res + }, {}) +} +export function initI18nAppMsgs() { + const name = 'uni.app.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { quit: 'Press back button again to exit' }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { quit: 'Pulse otra vez para salir' }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + quit: "Appuyez à nouveau pour quitter l'application", + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { quit: '再按一次退出应用' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { quit: '再按一次退出應用' }) + ) + } +} +export function initI18nAsyncMsgs() { + const name = 'uni.async.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + error: 'The connection timed out, click the screen to try again.', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + error: + 'Se agotó el tiempo de conexión, haga clic en la pantalla para volver a intentarlo.', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + error: "La connexion a expiré, cliquez sur l'écran pour réessayer.", + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { error: '连接服务器超时,点击屏幕重试' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { error: '連接服務器超時,點擊屏幕重試' }) + ) + } +} +export function initI18nShowActionSheetMsgs() { + const name = 'uni.showActionSheet.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add(LOCALE_EN, normalizeMessages(name, { cancel: 'Cancel' })) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add(LOCALE_ES, normalizeMessages(name, { cancel: 'Cancelar' })) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add(LOCALE_FR, normalizeMessages(name, { cancel: 'Annuler' })) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add(LOCALE_ZH_HANS, normalizeMessages(name, { cancel: '取消' })) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add(LOCALE_ZH_HANT, normalizeMessages(name, { cancel: '取消' })) + } +} +export function initI18nShowToastMsgs() { + const name = 'uni.showToast.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + unpaired: 'Please note showToast must be paired with hideToast', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + unpaired: + 'Tenga en cuenta que showToast debe estar emparejado con hideToast', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + unpaired: 'Veuillez noter que showToast doit être associé à hideToast', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + unpaired: '请注意 showToast 与 hideToast 必须配对使用', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + unpaired: '請注意 showToast 與 hideToast 必須配對使用', + }) + ) + } +} +export function initI18nShowLoadingMsgs() { + const name = 'uni.showLoading.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + unpaired: 'Please note showLoading must be paired with hideLoading', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + unpaired: + 'Tenga en cuenta que showLoading debe estar emparejado con hideLoading', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + unpaired: + 'Veuillez noter que showLoading doit être associé à hideLoading', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + unpaired: '请注意 showLoading 与 hideLoading 必须配对使用', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + unpaired: '請注意 showLoading 與 hideLoading 必須配對使用', + }) + ) + } +} +export function initI18nShowModalMsgs() { + const name = 'uni.showModal.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { cancel: 'Cancel', confirm: 'OK' }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { cancel: 'Cancelar', confirm: 'OK' }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { cancel: 'Annuler', confirm: 'OK' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { cancel: '取消', confirm: '确定' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { cancel: '取消', confirm: '確定' }) + ) + } +} +export function initI18nChooseImageMsgs() { + const name = 'uni.chooseImage.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + cancel: 'Cancel', + 'sourceType.album': 'Album', + 'sourceType.camera': 'Camera', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + cancel: 'Cancelar', + 'sourceType.album': 'Álbum', + 'sourceType.camera': 'Cámara', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + cancel: 'Annuler', + 'sourceType.album': 'Album', + 'sourceType.camera': 'Caméra', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + cancel: '取消', + 'sourceType.album': '从相册选择', + 'sourceType.camera': '拍摄', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + cancel: '取消', + 'sourceType.album': '從相冊選擇', + 'sourceType.camera': '拍攝', + }) + ) + } +} +export function initI18nChooseVideoMsgs() { + const name = 'uni.chooseVideo.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + cancel: 'Cancel', + 'sourceType.album': 'Album', + 'sourceType.camera': 'Camera', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + cancel: 'Cancelar', + 'sourceType.album': 'Álbum', + 'sourceType.camera': 'Cámara', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + cancel: 'Annuler', + 'sourceType.album': 'Album', + 'sourceType.camera': 'Caméra', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + cancel: '取消', + 'sourceType.album': '从相册选择', + 'sourceType.camera': '拍摄', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + cancel: '取消', + 'sourceType.album': '從相冊選擇', + 'sourceType.camera': '拍攝', + }) + ) + } +} +export function initI18nPreviewImageMsgs() { + const name = 'uni.previewImage.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + cancel: 'Cancel', + 'button.save': 'Save Image', + 'save.success': 'Saved successfully', + 'save.fail': 'Save failed', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + cancel: 'Cancelar', + 'button.save': 'Guardar imagen', + 'save.success': 'Guardado exitosamente', + 'save.fail': 'Error al guardar', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + cancel: 'Annuler', + 'button.save': 'Guardar imagen', + 'save.success': 'Enregistré avec succès', + 'save.fail': 'Échec de la sauvegarde', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + cancel: '取消', + 'button.save': '保存图像', + 'save.success': '保存图像到相册成功', + 'save.fail': '保存图像到相册失败', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + cancel: '取消', + 'button.save': '保存圖像', + 'save.success': '保存圖像到相冊成功', + 'save.fail': '保存圖像到相冊失敗', + }) + ) + } +} +export function initI18nSetClipboardDataMsgs() { + const name = 'uni.setClipboardData.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add(LOCALE_EN, normalizeMessages(name, { success: 'Content copied' })) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { success: 'Contenido copiado' }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add(LOCALE_FR, normalizeMessages(name, { success: 'Contenu copié' })) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add(LOCALE_ZH_HANS, normalizeMessages(name, { success: '内容已复制' })) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add(LOCALE_ZH_HANT, normalizeMessages(name, { success: '內容已復制' })) + } +} +export function initI18nScanCodeMsgs() { + const name = 'uni.scanCode.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + title: 'Scan code', + album: 'Album', + fail: 'Recognition failure', + 'flash.on': 'Tap to turn light on', + 'flash.off': 'Tap to turn light off', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + title: 'Código de escaneo', + album: 'Álbum', + fail: 'Échec de la reconnaissance', + 'flash.on': 'Toque para encender la luz', + 'flash.off': 'Toque para apagar la luz', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + title: 'Code d’analyse', + album: 'Album', + fail: 'Fallo de reconocimiento', + 'flash.on': "Appuyez pour activer l'éclairage", + 'flash.off': "Appuyez pour désactiver l'éclairage", + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + title: '扫码', + album: '相册', + fail: '识别失败', + 'flash.on': '轻触照亮', + 'flash.off': '轻触关闭', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + title: '掃碼', + album: '相冊', + fail: '識別失敗', + 'flash.on': '輕觸照亮', + 'flash.off': '輕觸關閉', + }) + ) + } +} +export function initI18nStartSoterAuthenticationMsgs() { + const name = 'uni.startSoterAuthentication.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { authContent: 'Fingerprint recognition' }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + authContent: 'Reconocimiento de huellas dactilares', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + authContent: "Reconnaissance de l'empreinte digitale", + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { authContent: '指纹识别中...' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { authContent: '指紋識別中...' }) + ) + } +} +export function initI18nPickerMsgs() { + const name = 'uni.picker.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { done: 'Done', cancel: 'Cancel' }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { done: 'OK', cancel: 'Cancelar' }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { done: 'OK', cancel: 'Annuler' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { done: '完成', cancel: '取消' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { done: '完成', cancel: '取消' }) + ) + } +} +export function initI18nVideoMsgs() { + const name = 'uni.video.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { danmu: 'Danmu', volume: 'Volume' }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { danmu: 'Danmu', volume: 'Volumen' }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { danmu: 'Danmu', volume: 'Le Volume' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { danmu: '弹幕', volume: '音量' }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { danmu: '彈幕', volume: '音量' }) + ) + } +} +export function initI18nButtonMsgs() { + const name = 'uni.button.' + if (__UNI_FEATURE_I18N_EN__) { + i18n.add( + LOCALE_EN, + normalizeMessages(name, { + 'feedback.title': 'feedback', + 'feedback.send': 'send', + }) + ) + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add( + LOCALE_ES, + normalizeMessages(name, { + 'feedback.title': 'realimentación', + 'feedback.send': 'enviar', + }) + ) + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add( + LOCALE_FR, + normalizeMessages(name, { + 'feedback.title': "retour d'information", + 'feedback.send': 'envoyer', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add( + LOCALE_ZH_HANS, + normalizeMessages(name, { + 'feedback.title': '问题反馈', + 'feedback.send': '发送', + }) + ) + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add( + LOCALE_ZH_HANT, + normalizeMessages(name, { + 'feedback.title': '問題反饋', + 'feedback.send': '發送', + }) + ) + } +} diff --git a/packages/uni-core/src/i18n/useI18n.ts b/packages/uni-core/src/i18n/useI18n.ts new file mode 100644 index 000000000..1e1c183b5 --- /dev/null +++ b/packages/uni-core/src/i18n/useI18n.ts @@ -0,0 +1,6 @@ +import { initVueI18n } from '@dcloudio/uni-i18n' +const i18n = initVueI18n() + +export function useI18n() { + return i18n +} diff --git a/packages/uni-core/src/helpers/i18n/zh-Hans.json b/packages/uni-core/src/i18n/zh-Hans.json similarity index 100% rename from packages/uni-core/src/helpers/i18n/zh-Hans.json rename to packages/uni-core/src/i18n/zh-Hans.json diff --git a/packages/uni-core/src/helpers/i18n/zh-Hant.json b/packages/uni-core/src/i18n/zh-Hant.json similarity index 100% rename from packages/uni-core/src/helpers/i18n/zh-Hant.json rename to packages/uni-core/src/i18n/zh-Hant.json diff --git a/packages/uni-core/src/index.ts b/packages/uni-core/src/index.ts index bf4b07117..9df09ed2d 100644 --- a/packages/uni-core/src/index.ts +++ b/packages/uni-core/src/index.ts @@ -1,3 +1,4 @@ +export * from './i18n' export * from './view' export * from './service' export * from './helpers' diff --git a/packages/uni-h5-vue/dist/vue.runtime.esm.js b/packages/uni-h5-vue/dist/vue.runtime.esm.js index 9ba6001fd..052a3bc5f 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.esm.js +++ b/packages/uni-h5-vue/dist/vue.runtime.esm.js @@ -6982,7 +6982,6 @@ function applyOptions$1(instance, options, deferredData = [], deferredWatch = [] } } } -// fixed by xxxxxx function callSyncHook(name, type, options, instance, globalMixins) { for (let i = 0; i < globalMixins.length; i++) { callHookWithMixinAndExtends(name, type, globalMixins[i], instance); @@ -9491,4 +9490,4 @@ function initApp(app) { } } -export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callSyncHook, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initApp, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; +export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initApp, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; diff --git a/packages/uni-h5-vue/lib/vue.runtime.esm.js b/packages/uni-h5-vue/lib/vue.runtime.esm.js index c1fac394b..2afff7026 100644 --- a/packages/uni-h5-vue/lib/vue.runtime.esm.js +++ b/packages/uni-h5-vue/lib/vue.runtime.esm.js @@ -6982,7 +6982,6 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [], } } } -// fixed by xxxxxx function callSyncHook(name, type, options, instance, globalMixins) { for (let i = 0; i < globalMixins.length; i++) { callHookWithMixinAndExtends(name, type, globalMixins[i], instance); @@ -9405,4 +9404,4 @@ const compile$1 = () => { } }; -export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callSyncHook, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; +export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index feb01d373..67e55bcd8 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -1,6 +1,6 @@ import {isFunction, extend, isPlainObject, invokeArrayFns, isString, hasOwn as hasOwn$1, hyphenate, isArray, isObject as isObject$1, capitalize, toRawType, makeMap as makeMap$1, isPromise} from "@vue/shared"; import {injectHook, isInSSRComponentSetup, createVNode, inject, provide, reactive, computed, nextTick, getCurrentInstance, onBeforeMount, onMounted, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, mergeProps, toDisplayString, ref, defineComponent, resolveComponent, toHandlers, renderSlot, createCommentVNode, onBeforeUnmount, withModifiers, withDirectives, vShow, vModelDynamic, createTextVNode, Fragment, renderList, vModelText, watch, withCtx, KeepAlive, resolveDynamicComponent} from "vue"; -import {passive, NAVBAR_HEIGHT, removeLeadingSlash, plusReady, debounce, PRIMARY_COLOR, getLen} from "@dcloudio/uni-shared"; +import {passive, NAVBAR_HEIGHT, removeLeadingSlash, plusReady, debounce, PRIMARY_COLOR as PRIMARY_COLOR$1, getLen} from "@dcloudio/uni-shared"; import {useRoute, createRouter, createWebHistory, createWebHashHistory, isNavigationFailure, RouterView} from "vue-router"; function applyOptions(options, instance2, publicThis) { Object.keys(options).forEach((name) => { @@ -106,6 +106,300 @@ function initApp$1(app) { globalProperties.$applyOptions = applyOptions; } } +const isObject = (val) => val !== null && typeof val === "object"; +class BaseFormatter { + constructor() { + this._caches = Object.create(null); + } + interpolate(message, values) { + if (!values) { + return [message]; + } + let tokens = this._caches[message]; + if (!tokens) { + tokens = parse(message); + this._caches[message] = tokens; + } + return compile(tokens, values); + } +} +const RE_TOKEN_LIST_VALUE = /^(?:\d)+/; +const RE_TOKEN_NAMED_VALUE = /^(?:\w)+/; +function parse(format) { + const tokens = []; + let position = 0; + let text2 = ""; + while (position < format.length) { + let char = format[position++]; + if (char === "{") { + if (text2) { + tokens.push({type: "text", value: text2}); + } + text2 = ""; + let sub = ""; + char = format[position++]; + while (char !== void 0 && char !== "}") { + sub += char; + char = format[position++]; + } + const isClosed = char === "}"; + const type = RE_TOKEN_LIST_VALUE.test(sub) ? "list" : isClosed && RE_TOKEN_NAMED_VALUE.test(sub) ? "named" : "unknown"; + tokens.push({value: sub, type}); + } else if (char === "%") { + if (format[position] !== "{") { + text2 += char; + } + } else { + text2 += char; + } + } + text2 && tokens.push({type: "text", value: text2}); + return tokens; +} +function compile(tokens, values) { + const compiled = []; + let index2 = 0; + const mode = Array.isArray(values) ? "list" : isObject(values) ? "named" : "unknown"; + if (mode === "unknown") { + return compiled; + } + while (index2 < tokens.length) { + const token = tokens[index2]; + switch (token.type) { + case "text": + compiled.push(token.value); + break; + case "list": + compiled.push(values[parseInt(token.value, 10)]); + break; + case "named": + if (mode === "named") { + compiled.push(values[token.value]); + } + break; + } + index2++; + } + return compiled; +} +const LOCALE_ZH_HANS = "zh-Hans"; +const LOCALE_ZH_HANT = "zh-Hant"; +const LOCALE_EN = "en"; +const LOCALE_FR = "fr"; +const LOCALE_ES = "es"; +const hasOwnProperty = Object.prototype.hasOwnProperty; +const hasOwn = (val, key) => hasOwnProperty.call(val, key); +const defaultFormatter = new BaseFormatter(); +function include(str, parts) { + return !!parts.find((part) => str.indexOf(part) !== -1); +} +function startsWith(str, parts) { + return parts.find((part) => str.indexOf(part) === 0); +} +function normalizeLocale(locale, messages) { + if (!locale) { + return; + } + locale = locale.trim().replace(/_/g, "-"); + if (messages[locale]) { + return locale; + } + locale = locale.toLowerCase(); + 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; + } +} +class I18n { + constructor({locale, fallbackLocale, messages, watcher, formater}) { + this.locale = LOCALE_EN; + this.fallbackLocale = LOCALE_EN; + this.message = {}; + this.messages = {}; + this.watchers = []; + if (fallbackLocale) { + this.fallbackLocale = fallbackLocale; + } + this.formater = formater || defaultFormatter; + this.messages = messages || {}; + this.setLocale(locale); + if (watcher) { + this.watchLocale(watcher); + } + } + setLocale(locale) { + const oldLocale = this.locale; + this.locale = normalizeLocale(locale, this.messages) || this.fallbackLocale; + this.message = this.messages[this.locale]; + this.watchers.forEach((watcher) => { + watcher(this.locale, oldLocale); + }); + } + getLocale() { + return this.locale; + } + watchLocale(fn) { + const index2 = this.watchers.push(fn) - 1; + return () => { + this.watchers.splice(index2, 1); + }; + } + add(locale, message) { + if (this.messages[locale]) { + Object.assign(this.messages[locale], message); + } else { + this.messages[locale] = message; + } + } + t(key, locale, values) { + let message = this.message; + if (typeof locale === "string") { + locale = normalizeLocale(locale, this.messages); + locale && (message = this.messages[locale]); + } else { + values = locale; + } + if (!hasOwn(message, key)) { + console.warn(`Cannot translate the value of keypath ${key}. Use the value of keypath as default.`); + return key; + } + return this.formater.interpolate(message[key], values).join(""); + } +} +function initLocaleWatcher(appVm2, i18n2) { + appVm2.$i18n && appVm2.$i18n.vm.$watch("locale", (newLocale) => { + i18n2.setLocale(newLocale); + }, { + immediate: true + }); +} +function getDefaultLocale() { + if (typeof navigator !== "undefined") { + return navigator.userLanguage || navigator.language; + } + if (typeof plus !== "undefined") { + return plus.os.language; + } + return uni.getSystemInfoSync().language; +} +function initVueI18n(messages = {}, fallbackLocale = LOCALE_EN, locale) { + const i18n2 = new I18n({ + locale: locale || fallbackLocale, + fallbackLocale, + messages + }); + let t2 = (key, values) => { + if (typeof getApp !== "function") { + t2 = function(key2, values2) { + return i18n2.t(key2, values2); + }; + } else { + const appVm2 = getApp().$vm; + if (!appVm2.$t || !appVm2.$i18n) { + if (!locale) { + i18n2.setLocale(getDefaultLocale()); + } + t2 = function(key2, values2) { + return i18n2.t(key2, values2); + }; + } else { + initLocaleWatcher(appVm2, i18n2); + t2 = function(key2, values2) { + const $i18n = appVm2.$i18n; + const silentTranslationWarn = $i18n.silentTranslationWarn; + $i18n.silentTranslationWarn = true; + const msg = appVm2.$t(key2, values2); + $i18n.silentTranslationWarn = silentTranslationWarn; + if (msg !== key2) { + return msg; + } + return i18n2.t(key2, $i18n.locale, values2); + }; + } + } + return t2(key, values); + }; + return { + i18n: i18n2, + t(key, values) { + return t2(key, values); + }, + add(locale2, message) { + return i18n2.add(locale2, message); + }, + getLocale() { + return i18n2.getLocale(); + }, + setLocale(newLocale) { + return i18n2.setLocale(newLocale); + } + }; +} +const i18n$1 = initVueI18n(); +function useI18n() { + return i18n$1; +} +const i18n = useI18n(); +function normalizeMessages(namespace, messages) { + return Object.keys(messages).reduce((res, name) => { + res[namespace + name] = messages[name]; + return res; + }, {}); +} +function initI18nAsyncMsgs() { + const name = "uni.async."; + if (__UNI_FEATURE_I18N_EN__) { + i18n.add(LOCALE_EN, normalizeMessages(name, { + error: "The connection timed out, click the screen to try again." + })); + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add(LOCALE_ES, normalizeMessages(name, { + error: "Se agot\xF3 el tiempo de conexi\xF3n, haga clic en la pantalla para volver a intentarlo." + })); + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add(LOCALE_FR, normalizeMessages(name, { + error: "La connexion a expir\xE9, cliquez sur l'\xE9cran pour r\xE9essayer." + })); + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add(LOCALE_ZH_HANS, normalizeMessages(name, {error: "\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5"})); + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add(LOCALE_ZH_HANT, normalizeMessages(name, {error: "\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66"})); + } +} +function initI18nShowModalMsgs() { + const name = "uni.showModal."; + if (__UNI_FEATURE_I18N_EN__) { + i18n.add(LOCALE_EN, normalizeMessages(name, {cancel: "Cancel", confirm: "OK"})); + } + if (__UNI_FEATURE_I18N_ES__) { + i18n.add(LOCALE_ES, normalizeMessages(name, {cancel: "Cancelar", confirm: "OK"})); + } + if (__UNI_FEATURE_I18N_FR__) { + i18n.add(LOCALE_FR, normalizeMessages(name, {cancel: "Annuler", confirm: "OK"})); + } + if (__UNI_FEATURE_I18N_ZH_HANS__) { + i18n.add(LOCALE_ZH_HANS, normalizeMessages(name, {cancel: "\u53D6\u6D88", confirm: "\u786E\u5B9A"})); + } + if (__UNI_FEATURE_I18N_ZH_HANT__) { + i18n.add(LOCALE_ZH_HANT, normalizeMessages(name, {cancel: "\u53D6\u6D88", confirm: "\u78BA\u5B9A"})); + } +} function E() { } E.prototype = { @@ -823,426 +1117,6 @@ function createSvgIconVNode(path, color = "#000", size = 27) { }, null, 8, ["d", "fill"]) ], 8, ["width", "height"]); } -const isObject = (val) => val !== null && typeof val === "object"; -class BaseFormatter { - constructor() { - this._caches = Object.create(null); - } - interpolate(message, values) { - if (!values) { - return [message]; - } - let tokens = this._caches[message]; - if (!tokens) { - tokens = parse(message); - this._caches[message] = tokens; - } - return compile(tokens, values); - } -} -const RE_TOKEN_LIST_VALUE = /^(?:\d)+/; -const RE_TOKEN_NAMED_VALUE = /^(?:\w)+/; -function parse(format) { - const tokens = []; - let position = 0; - let text2 = ""; - while (position < format.length) { - let char = format[position++]; - if (char === "{") { - if (text2) { - tokens.push({type: "text", value: text2}); - } - text2 = ""; - let sub = ""; - char = format[position++]; - while (char !== void 0 && char !== "}") { - sub += char; - char = format[position++]; - } - const isClosed = char === "}"; - const type = RE_TOKEN_LIST_VALUE.test(sub) ? "list" : isClosed && RE_TOKEN_NAMED_VALUE.test(sub) ? "named" : "unknown"; - tokens.push({value: sub, type}); - } else if (char === "%") { - if (format[position] !== "{") { - text2 += char; - } - } else { - text2 += char; - } - } - text2 && tokens.push({type: "text", value: text2}); - return tokens; -} -function compile(tokens, values) { - const compiled = []; - let index2 = 0; - const mode = Array.isArray(values) ? "list" : isObject(values) ? "named" : "unknown"; - if (mode === "unknown") { - return compiled; - } - while (index2 < tokens.length) { - const token = tokens[index2]; - switch (token.type) { - case "text": - compiled.push(token.value); - break; - case "list": - compiled.push(values[parseInt(token.value, 10)]); - break; - case "named": - if (mode === "named") { - compiled.push(values[token.value]); - } - break; - } - index2++; - } - return compiled; -} -const hasOwnProperty = Object.prototype.hasOwnProperty; -const hasOwn = (val, key) => hasOwnProperty.call(val, key); -const defaultFormatter = new BaseFormatter(); -function include(str, parts) { - return !!parts.find((part) => str.indexOf(part) !== -1); -} -function startsWith(str, parts) { - return parts.find((part) => str.indexOf(part) === 0); -} -function normalizeLocale(locale, messages2) { - if (!locale) { - return; - } - locale = locale.trim().replace(/_/g, "-"); - if (messages2[locale]) { - return locale; - } - locale = locale.toLowerCase(); - if (locale.indexOf("zh") === 0) { - if (locale.indexOf("-hans") !== -1) { - return "zh-Hans"; - } - if (locale.indexOf("-hant") !== -1) { - return "zh-Hant"; - } - if (include(locale, ["-tw", "-hk", "-mo", "-cht"])) { - return "zh-Hant"; - } - return "zh-Hans"; - } - const lang = startsWith(locale, ["en", "fr", "es"]); - if (lang) { - return lang; - } -} -class I18n { - constructor({locale, fallbackLocale: fallbackLocale2, messages: messages2, watcher, formater}) { - this.locale = "en"; - this.fallbackLocale = "en"; - this.message = {}; - this.messages = {}; - this.watchers = []; - if (fallbackLocale2) { - this.fallbackLocale = fallbackLocale2; - } - this.formater = formater || defaultFormatter; - this.messages = messages2; - this.setLocale(locale); - if (watcher) { - this.watchLocale(watcher); - } - } - setLocale(locale) { - const oldLocale = this.locale; - this.locale = normalizeLocale(locale, this.messages) || this.fallbackLocale; - this.message = this.messages[this.locale]; - this.watchers.forEach((watcher) => { - watcher(this.locale, oldLocale); - }); - } - getLocale() { - return this.locale; - } - watchLocale(fn) { - const index2 = this.watchers.push(fn) - 1; - return () => { - this.watchers.splice(index2, 1); - }; - } - mergeLocaleMessage(locale, message) { - if (this.messages[locale]) { - Object.assign(this.messages[locale], message); - } else { - this.messages[locale] = message; - } - } - t(key, locale, values) { - let message = this.message; - if (typeof locale === "string") { - locale = normalizeLocale(locale, this.messages); - locale && (message = this.messages[locale]); - } else { - values = locale; - } - if (!hasOwn(message, key)) { - console.warn(`Cannot translate the value of keypath ${key}. Use the value of keypath as default.`); - return key; - } - return this.formater.interpolate(message[key], values).join(""); - } -} -function initLocaleWatcher(appVm2, i18n2) { - appVm2.$i18n && appVm2.$i18n.vm.$watch("locale", (newLocale) => { - i18n2.setLocale(newLocale); - }, { - immediate: true - }); -} -function getDefaultLocale() { - if (typeof navigator !== "undefined") { - return navigator.userLanguage || navigator.language; - } - if (typeof plus !== "undefined") { - return plus.os.language; - } - return uni.getSystemInfoSync().language; -} -function initVueI18n(messages2, fallbackLocale2 = "en", locale) { - const i18n2 = new I18n({ - locale: locale || fallbackLocale2, - fallbackLocale: fallbackLocale2, - messages: messages2 - }); - let t2 = (key, values) => { - if (typeof getApp !== "function") { - t2 = function(key2, values2) { - return i18n2.t(key2, values2); - }; - } else { - const appVm2 = getApp().$vm; - if (!appVm2.$t || !appVm2.$i18n) { - if (!locale) { - i18n2.setLocale(getDefaultLocale()); - } - t2 = function(key2, values2) { - return i18n2.t(key2, values2); - }; - } else { - initLocaleWatcher(appVm2, i18n2); - t2 = function(key2, values2) { - const $i18n = appVm2.$i18n; - const silentTranslationWarn = $i18n.silentTranslationWarn; - $i18n.silentTranslationWarn = true; - const msg = appVm2.$t(key2, values2); - $i18n.silentTranslationWarn = silentTranslationWarn; - if (msg !== key2) { - return msg; - } - return i18n2.t(key2, $i18n.locale, values2); - }; - } - } - return t2(key, values); - }; - return { - i18n: i18n2, - t(key, values) { - return t2(key, values); - }, - getLocale() { - return i18n2.getLocale(); - }, - setLocale(newLocale) { - return i18n2.setLocale(newLocale); - }, - mixin: { - beforeCreate() { - const unwatch = i18n2.watchLocale(() => { - this.$forceUpdate(); - }); - this.$once("hook:beforeDestroy", function() { - unwatch(); - }); - }, - methods: { - $$t(key, values) { - return t2(key, values); - } - } - } - }; -} -var en = { - "uni.app.quit": "Press back button again to exit", - "uni.async.error": "The connection timed out, click the screen to try again.", - "uni.showActionSheet.cancel": "Cancel", - "uni.showToast.unpaired": "Please note showToast must be paired with hideToast", - "uni.showLoading.unpaired": "Please note showLoading must be paired with hideLoading", - "uni.showModal.cancel": "Cancel", - "uni.showModal.confirm": "OK", - "uni.chooseImage.cancel": "Cancel", - "uni.chooseImage.sourceType.album": "Album", - "uni.chooseImage.sourceType.camera": "Camera", - "uni.chooseVideo.cancel": "Cancel", - "uni.chooseVideo.sourceType.album": "Album", - "uni.chooseVideo.sourceType.camera": "Camera", - "uni.previewImage.cancel": "Cancel", - "uni.previewImage.button.save": "Save Image", - "uni.previewImage.save.success": "Saved successfully", - "uni.previewImage.save.fail": "Save failed", - "uni.setClipboardData.success": "Content copied", - "uni.scanCode.title": "Scan code", - "uni.scanCode.album": "Album", - "uni.scanCode.fail": "Recognition failure", - "uni.scanCode.flash.on": "Tap to turn light on", - "uni.scanCode.flash.off": "Tap to turn light off", - "uni.startSoterAuthentication.authContent": "Fingerprint recognition", - "uni.picker.done": "Done", - "uni.picker.cancel": "Cancel", - "uni.video.danmu": "Danmu", - "uni.video.volume": "Volume", - "uni.button.feedback.title": "feedback", - "uni.button.feedback.send": "send" -}; -var es = { - "uni.app.quit": "Pulse otra vez para salir", - "uni.async.error": "Se agot\xF3 el tiempo de conexi\xF3n, haga clic en la pantalla para volver a intentarlo.", - "uni.showActionSheet.cancel": "Cancelar", - "uni.showToast.unpaired": "Tenga en cuenta que showToast debe estar emparejado con hideToast", - "uni.showLoading.unpaired": "Tenga en cuenta que showLoading debe estar emparejado con hideLoading", - "uni.showModal.cancel": "Cancelar", - "uni.showModal.confirm": "OK", - "uni.chooseImage.cancel": "Cancelar", - "uni.chooseImage.sourceType.album": "\xC1lbum", - "uni.chooseImage.sourceType.camera": "C\xE1mara", - "uni.chooseVideo.cancel": "Cancelar", - "uni.chooseVideo.sourceType.album": "\xC1lbum", - "uni.chooseVideo.sourceType.camera": "C\xE1mara", - "uni.previewImage.cancel": "Cancelar", - "uni.previewImage.button.save": "Guardar imagen", - "uni.previewImage.save.success": "Guardado exitosamente", - "uni.previewImage.save.fail": "Error al guardar", - "uni.setClipboardData.success": "Contenido copiado", - "uni.scanCode.title": "C\xF3digo de escaneo", - "uni.scanCode.album": "\xC1lbum", - "uni.scanCode.fail": "\xC9chec de la reconnaissance", - "uni.scanCode.flash.on": "Toque para encender la luz", - "uni.scanCode.flash.off": "Toque para apagar la luz", - "uni.startSoterAuthentication.authContent": "Reconocimiento de huellas dactilares", - "uni.picker.done": "OK", - "uni.picker.cancel": "Cancelar", - "uni.video.danmu": "Danmu", - "uni.video.volume": "Volumen", - "uni.button.feedback.title": "realimentaci\xF3n", - "uni.button.feedback.send": "enviar" -}; -var fr = { - "uni.app.quit": "Appuyez \xE0 nouveau pour quitter l'application", - "uni.async.error": "La connexion a expir\xE9, cliquez sur l'\xE9cran pour r\xE9essayer.", - "uni.showActionSheet.cancel": "Annuler", - "uni.showToast.unpaired": "Veuillez noter que showToast doit \xEAtre associ\xE9 \xE0 hideToast", - "uni.showLoading.unpaired": "Veuillez noter que showLoading doit \xEAtre associ\xE9 \xE0 hideLoading", - "uni.showModal.cancel": "Annuler", - "uni.showModal.confirm": "OK", - "uni.chooseImage.cancel": "Annuler", - "uni.chooseImage.sourceType.album": "Album", - "uni.chooseImage.sourceType.camera": "Cam\xE9ra", - "uni.chooseVideo.cancel": "Annuler", - "uni.chooseVideo.sourceType.album": "Album", - "uni.chooseVideo.sourceType.camera": "Cam\xE9ra", - "uni.previewImage.cancel": "Annuler", - "uni.previewImage.button.save": "Guardar imagen", - "uni.previewImage.save.success": "Enregistr\xE9 avec succ\xE8s", - "uni.previewImage.save.fail": "\xC9chec de la sauvegarde", - "uni.setClipboardData.success": "Contenu copi\xE9", - "uni.scanCode.title": "Code d\u2019analyse", - "uni.scanCode.album": "Album", - "uni.scanCode.fail": "Fallo de reconocimiento", - "uni.scanCode.flash.on": "Appuyez pour activer l'\xE9clairage", - "uni.scanCode.flash.off": "Appuyez pour d\xE9sactiver l'\xE9clairage", - "uni.startSoterAuthentication.authContent": "Reconnaissance de l'empreinte digitale", - "uni.picker.done": "OK", - "uni.picker.cancel": "Annuler", - "uni.video.danmu": "Danmu", - "uni.video.volume": "Le Volume", - "uni.button.feedback.title": "retour d'information", - "uni.button.feedback.send": "envoyer" -}; -var zhHans = { - "uni.app.quit": "\u518D\u6309\u4E00\u6B21\u9000\u51FA\u5E94\u7528", - "uni.async.error": "\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5", - "uni.showActionSheet.cancel": "\u53D6\u6D88", - "uni.showToast.unpaired": "\u8BF7\u6CE8\u610F showToast \u4E0E hideToast \u5FC5\u987B\u914D\u5BF9\u4F7F\u7528", - "uni.showLoading.unpaired": "\u8BF7\u6CE8\u610F showLoading \u4E0E hideLoading \u5FC5\u987B\u914D\u5BF9\u4F7F\u7528", - "uni.showModal.cancel": "\u53D6\u6D88", - "uni.showModal.confirm": "\u786E\u5B9A", - "uni.chooseImage.cancel": "\u53D6\u6D88", - "uni.chooseImage.sourceType.album": "\u4ECE\u76F8\u518C\u9009\u62E9", - "uni.chooseImage.sourceType.camera": "\u62CD\u6444", - "uni.chooseVideo.cancel": "\u53D6\u6D88", - "uni.chooseVideo.sourceType.album": "\u4ECE\u76F8\u518C\u9009\u62E9", - "uni.chooseVideo.sourceType.camera": "\u62CD\u6444", - "uni.previewImage.cancel": "\u53D6\u6D88", - "uni.previewImage.button.save": "\u4FDD\u5B58\u56FE\u50CF", - "uni.previewImage.save.success": "\u4FDD\u5B58\u56FE\u50CF\u5230\u76F8\u518C\u6210\u529F", - "uni.previewImage.save.fail": "\u4FDD\u5B58\u56FE\u50CF\u5230\u76F8\u518C\u5931\u8D25", - "uni.setClipboardData.success": "\u5185\u5BB9\u5DF2\u590D\u5236", - "uni.scanCode.title": "\u626B\u7801", - "uni.scanCode.album": "\u76F8\u518C", - "uni.scanCode.fail": "\u8BC6\u522B\u5931\u8D25", - "uni.scanCode.flash.on": "\u8F7B\u89E6\u7167\u4EAE", - "uni.scanCode.flash.off": "\u8F7B\u89E6\u5173\u95ED", - "uni.startSoterAuthentication.authContent": "\u6307\u7EB9\u8BC6\u522B\u4E2D...", - "uni.picker.done": "\u5B8C\u6210", - "uni.picker.cancel": "\u53D6\u6D88", - "uni.video.danmu": "\u5F39\u5E55", - "uni.video.volume": "\u97F3\u91CF", - "uni.button.feedback.title": "\u95EE\u9898\u53CD\u9988", - "uni.button.feedback.send": "\u53D1\u9001" -}; -var zhHant = { - "uni.app.quit": "\u518D\u6309\u4E00\u6B21\u9000\u51FA\u61C9\u7528", - "uni.async.error": "\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66", - "uni.showActionSheet.cancel": "\u53D6\u6D88", - "uni.showToast.unpaired": "\u8ACB\u6CE8\u610F showToast \u8207 hideToast \u5FC5\u9808\u914D\u5C0D\u4F7F\u7528", - "uni.showLoading.unpaired": "\u8ACB\u6CE8\u610F showLoading \u8207 hideLoading \u5FC5\u9808\u914D\u5C0D\u4F7F\u7528", - "uni.showModal.cancel": "\u53D6\u6D88", - "uni.showModal.confirm": "\u78BA\u5B9A", - "uni.chooseImage.cancel": "\u53D6\u6D88", - "uni.chooseImage.sourceType.album": "\u5F9E\u76F8\u518A\u9078\u64C7", - "uni.chooseImage.sourceType.camera": "\u62CD\u651D", - "uni.chooseVideo.cancel": "\u53D6\u6D88", - "uni.chooseVideo.sourceType.album": "\u5F9E\u76F8\u518A\u9078\u64C7", - "uni.chooseVideo.sourceType.camera": "\u62CD\u651D", - "uni.previewImage.cancel": "\u53D6\u6D88", - "uni.previewImage.button.save": "\u4FDD\u5B58\u5716\u50CF", - "uni.previewImage.save.success": "\u4FDD\u5B58\u5716\u50CF\u5230\u76F8\u518A\u6210\u529F", - "uni.previewImage.save.fail": "\u4FDD\u5B58\u5716\u50CF\u5230\u76F8\u518A\u5931\u6557", - "uni.setClipboardData.success": "\u5167\u5BB9\u5DF2\u5FA9\u5236", - "uni.scanCode.title": "\u6383\u78BC", - "uni.scanCode.album": "\u76F8\u518A", - "uni.scanCode.fail": "\u8B58\u5225\u5931\u6557", - "uni.scanCode.flash.on": "\u8F15\u89F8\u7167\u4EAE", - "uni.scanCode.flash.off": "\u8F15\u89F8\u95DC\u9589", - "uni.startSoterAuthentication.authContent": "\u6307\u7D0B\u8B58\u5225\u4E2D...", - "uni.picker.done": "\u5B8C\u6210", - "uni.picker.cancel": "\u53D6\u6D88", - "uni.video.danmu": "\u5F48\u5E55", - "uni.video.volume": "\u97F3\u91CF", - "uni.button.feedback.title": "\u554F\u984C\u53CD\u994B", - "uni.button.feedback.send": "\u767C\u9001" -}; -const messages = { - en, - es, - fr, - "zh-Hans": zhHans, - "zh-Hant": zhHant -}; -const fallbackLocale = "en"; -const i18n = /* @__PURE__ */ initVueI18n(messages, fallbackLocale); -function useI18n() { - return i18n; -} function getRealRoute(fromRoute, toRoute) { if (!toRoute) { toRoute = fromRoute; @@ -3850,11 +3724,11 @@ const CANCEL_COLOR = "#f43530"; const ICONS = { success: { d: ICON_PATH_SUCCESS, - c: PRIMARY_COLOR + c: PRIMARY_COLOR$1 }, success_no_circle: { d: ICON_PATH_SUCCESS_NO_CIRCLE, - c: PRIMARY_COLOR + c: PRIMARY_COLOR$1 }, info: { d: ICON_PATH_INFO, @@ -3874,7 +3748,7 @@ const ICONS = { }, download: { d: ICON_PATH_DOWNLOAD, - c: PRIMARY_COLOR + c: PRIMARY_COLOR$1 }, search: { d: ICON_PATH_SEARCH, @@ -4372,7 +4246,14 @@ function formatApiArgs(args, options) { } const formatArgs = options.formatArgs; Object.keys(formatArgs).forEach((name) => { - formatArgs[name](args[0][name], params); + const formatterOrDefaultValue = formatArgs[name]; + if (isFunction(formatterOrDefaultValue)) { + formatterOrDefaultValue(args[0][name], params); + } else { + if (!hasOwn$1(params, name)) { + params[name] = formatterOrDefaultValue; + } + } }); return args; } @@ -4776,28 +4657,16 @@ function stringifyQuery(url, data) { return url + (query ? "?" + query : "") + (hash ? "#" + hash : ""); } const RequestProtocol = { - method: { - type: String - }, - data: { - type: [Object, String, Array, ArrayBuffer] - }, + method: String, + data: [Object, String, Array, ArrayBuffer], url: { type: String, required: true }, - header: { - type: Object - }, - dataType: { - type: String - }, - responseType: { - type: String - }, - withCredentials: { - type: Boolean - } + header: Object, + dataType: String, + responseType: String, + withCredentials: Boolean }; const RequestOptions = { formatArgs: { @@ -4863,9 +4732,7 @@ const UploadFileProtocol = { type: String, required: true }, - files: { - type: Array - }, + files: Array, filePath: String, name: String, header: Object, @@ -5064,6 +4931,96 @@ const SetNavigationBarTitleProtocol = { }; const API_SHOW_NAVIGATION_BAR_LOADING = "showNavigationBarLoading"; const API_HIDE_NAVIGATION_BAR_LOADING = "hideNavigationBarLoading"; +const PRIMARY_COLOR = "#007aff"; +const API_SHOW_MODAL = "showModal"; +const {t: t$1} = useI18n(); +const ShowModalProtocol = { + title: String, + content: String, + showCancel: Boolean, + cancelText: String, + cancelColor: String, + confirmText: String, + confirmColor: String +}; +let isInitI18nShowModalMsgs = false; +const ShowModalOptions = { + beforeInvoke() { + if (isInitI18nShowModalMsgs) { + return; + } + isInitI18nShowModalMsgs = true; + initI18nShowModalMsgs(); + }, + formatArgs: { + title: "", + content: "", + showCancel: true, + cancelText(_value, params) { + if (!hasOwn$1(params, "cancelText")) { + params.cancelText = t$1("uni.showModal.cancel"); + } + }, + cancelColor: "#000", + confirmText(_value, params) { + if (!hasOwn$1(params, "confirmText")) { + params.confirmText = t$1("uni.showModal.confirm"); + } + }, + confirmColor: PRIMARY_COLOR + } +}; +const API_SHOW_TOAST = "showToast"; +const ShowToastProtocol = { + title: String, + icon: String, + image: String, + duration: Number, + mask: Boolean +}; +const ShowToastOptions = { + formatArgs: { + title: "", + icon(value, params) { + if (["success", "loading", "none"].indexOf(value) === -1) { + params.icon = "success"; + } + }, + image(value, params) { + if (value) { + params.image = getRealPath(value); + } + }, + duration: 1500, + mask: false + } +}; +const API_SHOW_LOADING = "showLoading"; +const ShowLoadingProtocol = { + title: String, + mask: Boolean +}; +const ShowLoadingOptions = { + formatArgs: { + title: "", + mask: false + } +}; +const API_SHOW_ACTION_SHEET = "showActionSheet"; +const ShowActionSheetProtocol = { + itemList: { + type: Array, + required: true + }, + itemColor: String +}; +const ShowActionSheetOptions = { + formatArgs: { + itemColor: "#000" + } +}; +const API_HIDE_TOAST = "hideToast"; +const API_HIDE_LOADING = "hideLoading"; const IndexProtocol = { index: { type: Number, @@ -11186,6 +11143,18 @@ const hideNavigationBarLoading = /* @__PURE__ */ defineAsyncApi(API_HIDE_NAVIGAT const setNavigationBarTitle = /* @__PURE__ */ defineAsyncApi(API_SET_NAVIGATION_BAR_TITLE, (args, {resolve, reject}) => { setNavigationBar(getCurrentPageMeta(), API_SET_NAVIGATION_BAR_TITLE, args, resolve, reject); }, SetNavigationBarTitleProtocol); +const showModal = /* @__PURE__ */ defineAsyncApi(API_SHOW_MODAL, () => { +}, ShowModalProtocol, ShowModalOptions); +const showToast = /* @__PURE__ */ defineAsyncApi(API_SHOW_TOAST, () => { +}, ShowToastProtocol, ShowToastOptions); +const hideToast = /* @__PURE__ */ defineAsyncApi(API_HIDE_TOAST, () => { +}); +const showLoading = /* @__PURE__ */ defineAsyncApi(API_SHOW_LOADING, () => { +}, ShowLoadingProtocol, ShowLoadingOptions); +const hideLoading = /* @__PURE__ */ defineAsyncApi(API_HIDE_LOADING, () => { +}); +const showActionSheet = /* @__PURE__ */ defineAsyncApi(API_SHOW_ACTION_SHEET, () => { +}, ShowActionSheetProtocol, ShowActionSheetOptions); let tabBar; function useTabBar() { if (!tabBar) { @@ -11328,6 +11297,12 @@ var api = /* @__PURE__ */ Object.freeze({ showNavigationBarLoading, hideNavigationBarLoading, setNavigationBarTitle, + showModal, + showToast, + hideToast, + showLoading, + hideLoading, + showActionSheet, setTabBarItem, setTabBarStyle, hideTabBar, @@ -12345,6 +12320,7 @@ function createPageBodyVNode(ctx) { }); } var index_vue_vue_type_style_index_0_lang$1 = "\n.uni-async-error {\r\n position: absolute;\r\n left: 0;\r\n right: 0;\r\n top: 0;\r\n bottom: 0;\r\n color: #999;\r\n padding: 100px 10px;\r\n text-align: center;\n}\r\n"; +initI18nAsyncMsgs(); const _sfc_main$1 = { name: "AsyncError", setup() { @@ -12376,4 +12352,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { ]); } _sfc_main.render = _sfc_render; -export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$n as Audio, index$4 as Button, _sfc_main$m as Canvas, _sfc_main$l as Checkbox, _sfc_main$k as CheckboxGroup, _sfc_main$j as Editor, index$5 as Form, index$3 as Icon, _sfc_main$h as Image, _sfc_main$g as Input, _sfc_main$f as Label, LayoutComponent, _sfc_main$e as MovableView, _sfc_main$d as Navigator, index as PageComponent, _sfc_main$c as Progress, _sfc_main$b as Radio, _sfc_main$a as RadioGroup, _sfc_main$i as ResizeSensor, _sfc_main$9 as RichText, _sfc_main$8 as ScrollView, _sfc_main$7 as Slider, _sfc_main$6 as SwiperItem, _sfc_main$5 as Switch, index$2 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as Video, index$1 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getNetworkType, getSystemInfo, getSystemInfoSync, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, makePhoneCall, navigateBack, navigateTo, offNetworkStatusChange, onNetworkStatusChange, onTabBarMidButtonTap, openDocument, index$6 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeTabBarBadge, request, setNavigationBarColor, setNavigationBarTitle, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showNavigationBarLoading, showTabBar, showTabBarRedDot, switchTab, uni$1 as uni, uploadFile, upx2px, useSubscribe}; +export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$n as Audio, index$4 as Button, _sfc_main$m as Canvas, _sfc_main$l as Checkbox, _sfc_main$k as CheckboxGroup, _sfc_main$j as Editor, index$5 as Form, index$3 as Icon, _sfc_main$h as Image, _sfc_main$g as Input, _sfc_main$f as Label, LayoutComponent, _sfc_main$e as MovableView, _sfc_main$d as Navigator, index as PageComponent, _sfc_main$c as Progress, _sfc_main$b as Radio, _sfc_main$a as RadioGroup, _sfc_main$i as ResizeSensor, _sfc_main$9 as RichText, _sfc_main$8 as ScrollView, _sfc_main$7 as Slider, _sfc_main$6 as SwiperItem, _sfc_main$5 as Switch, index$2 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as Video, index$1 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getNetworkType, getSystemInfo, getSystemInfoSync, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, hideToast, makePhoneCall, navigateBack, navigateTo, offNetworkStatusChange, onNetworkStatusChange, onTabBarMidButtonTap, openDocument, index$6 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeTabBarBadge, request, setNavigationBarColor, setNavigationBarTitle, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showActionSheet, showLoading, showModal, showNavigationBarLoading, showTabBar, showTabBarRedDot, showToast, switchTab, uni$1 as uni, uploadFile, upx2px, useSubscribe}; diff --git a/packages/uni-h5/src/framework/components/async-error/index.vue b/packages/uni-h5/src/framework/components/async-error/index.vue index f8ce25b69..ba8da857e 100644 --- a/packages/uni-h5/src/framework/components/async-error/index.vue +++ b/packages/uni-h5/src/framework/components/async-error/index.vue @@ -15,9 +15,10 @@