提交 e4689ce1 编写于 作者: fxy060608's avatar fxy060608

wip(i18n): sync i18n locale

上级 5b56d530
......@@ -50,6 +50,7 @@ declare var __UNI_FEATURE_NAVIGATIONBAR__: boolean
declare var __UNI_FEATURE_NAVIGATIONBAR_BUTTONS__: boolean
declare var __UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__: boolean
declare var __UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__: boolean
declare var __UNI_FEATURE_I18N_LOCALE__: boolean
declare var __UNI_FEATURE_I18N_EN__: boolean
declare var __UNI_FEATURE_I18N_ES__: boolean
declare var __UNI_FEATURE_I18N_FR__: boolean
......
......@@ -32,6 +32,6 @@
"compression": "^1.7.4",
"cypress": "^7.3.0",
"serve-static": "^1.14.1",
"vite": "^2.5.1"
"vite": "2.5.1"
}
}
......@@ -54,10 +54,10 @@
lodash.once "^4.1.1"
"@dcloudio/uni-app@../../uni-app":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-cli-shared@../../uni-cli-shared":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
dependencies:
"@rollup/pluginutils" "^4.1.1"
chokidar "^3.5.2"
......@@ -73,19 +73,19 @@
xregexp "3.1.0"
"@dcloudio/uni-cloud@../../uni-cloud":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-components@../../uni-components":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-h5-vite@../../uni-h5-vite":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-h5-vue@../../uni-h5-vue":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-h5@../../uni-h5":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
dependencies:
localstorage-polyfill "^1.0.1"
pako "^2.0.3"
......@@ -93,16 +93,16 @@
xmlhttprequest "^1.8.0"
"@dcloudio/uni-i18n@../../uni-i18n":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-shared@../../uni-shared":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/uni-stat@../../uni-stat":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
"@dcloudio/vite-plugin-uni@../../vite-plugin-uni":
version "3.0.0-alpha-3000020210813002"
version "3.0.0-alpha-3000020210827004"
dependencies:
"@rollup/pluginutils" "^4.1.0"
autoprefixer "^10.2.5"
......@@ -171,9 +171,9 @@
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==
"@types/node@*":
version "16.7.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.2.tgz#0465a39b5456b61a04d98bd5545f8b34be340cb7"
integrity sha512-TbG4TOx9hng8FKxaVrCisdaxKxqEwJ3zwHoCWXZ0Jw6mnvTInpaB99/2Cy4+XxpXtjNv9/TgfGSvZFyfV/t8Fw==
version "16.7.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.8.tgz#2448be5f24fe6b77114632b6350fcd219334651e"
integrity sha512-8upnoQU0OPzbIkm+ZMM0zCeFCkw2s3mS0IWdx0+AAaWqm4fkBb0UJp8Edl7FVKRamYbpJC/aVsHpKWBIbiC7Zg==
"@types/node@^14.14.31":
version "14.17.12"
......@@ -412,12 +412,12 @@ at-least-node@^1.0.0:
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
autoprefixer@^10.2.5:
version "10.3.2"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.3.2.tgz#836e4b4f59eb6876c41012c1c937be74035f3ec8"
integrity sha512-RHKq0YCvhxAn9987n0Gl6lkzLd39UKwCkUPMFE0cHhxU0SvcTjBxWG/CtkZ4/HvbqK9U5V8j03nAcGBlX3er/Q==
version "10.3.3"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.3.3.tgz#4bac89c74ef98e6a40fe1c5b76c0d1c91db153ce"
integrity sha512-yRzjxfnggrP/+qVHlUuZz5FZzEbkT+Yt0/Df6ScEMnbbZBLzYB2W0KLxoQCW+THm1SpOsM1ZPcTHAwuvmibIsQ==
dependencies:
browserslist "^4.16.8"
caniuse-lite "^1.0.30001251"
caniuse-lite "^1.0.30001252"
colorette "^1.3.0"
fraction.js "^4.1.1"
normalize-range "^0.1.2"
......@@ -532,10 +532,10 @@ cachedir@^2.3.0:
resolved "https://registry.yarnpkg.com/cachedir/-/cachedir-2.3.0.tgz#0c75892a052198f0b21c7c1804d8331edfcae0e8"
integrity sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw==
caniuse-lite@^1.0.30001251:
version "1.0.30001251"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001251.tgz#6853a606ec50893115db660f82c094d18f096d85"
integrity sha512-HOe1r+9VkU4TFmnU70z+r7OLmtR+/chB1rdcJUeQlAinjEeb0cKL20tlAtOagNZhbrtLnCvV19B4FmF1rgzl6A==
caniuse-lite@^1.0.30001251, caniuse-lite@^1.0.30001252:
version "1.0.30001252"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001252.tgz#cb16e4e3dafe948fc4a9bb3307aea054b912019a"
integrity sha512-I56jhWDGMtdILQORdusxBOH+Nl/KgQSdDmpJezYddnAkVOmnoU8zwjTV9xAjMIYxr0iPreEAVylCGcmHCjfaOw==
caseless@~0.12.0:
version "0.12.0"
......@@ -843,9 +843,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
electron-to-chromium@^1.3.811:
version "1.3.818"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.818.tgz#32ed024fa8316e5d469c96eecbea7d2463d80085"
integrity sha512-c/Z9gIr+jDZAR9q+mn40hEc1NharBT+8ejkarjbCDnBNFviI6hvcC5j2ezkAXru//bTnQp5n6iPi0JA83Tla1Q==
version "1.3.824"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.824.tgz#9f85cc826c70b12180009d461e3b19c8121a56d2"
integrity sha512-Fk+5aD0HDi9i9ZKt9n2VPOZO1dQy7PV++hz2wJ/KIn+CvVfu4fny39squHtyVDPuHNuoJGAZIbuReEklqYIqfA==
emoji-regex@^8.0.0:
version "8.0.0"
......@@ -877,9 +877,9 @@ enquirer@^2.3.6:
ansi-colors "^4.1.1"
esbuild@^0.12.17:
version "0.12.22"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.22.tgz#6031a1257b8d0307d306bed673b79c3668607f51"
integrity sha512-yWCr9RoFehpqoe/+MwZXJpYOEIt7KOEvNnjIeMZpMSyQt+KCBASM3y7yViiN5dJRphf1wGdUz1+M4rTtWd/ulA==
version "0.12.24"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.24.tgz#21966fad25a80f368ed308101e88102bce0dc68f"
integrity sha512-C0ibY+HsXzYB6L/pLWEiWjMpghKsIc58Q5yumARwBQsHl9DXPakW+5NI/Y9w4YXiz0PEP6XTGTT/OV4Nnsmb4A==
escalade@^3.1.1:
version "3.1.1"
......@@ -2309,10 +2309,10 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"
vite@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.1.tgz#953c71a034c07b3ae0448d57664ec9c6862f23a8"
integrity sha512-FwmLbbz8MB1pBs9dKoRDgpiqoijif8hSK1+NNUYc12/cnf+pM2UFhhQ1rcpXgbMhm/5c2USZdVAf0FSkSxaFDA==
vite@^2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.2.tgz#3963a4ec1e6ecae49359eddfdd67f6cb1e6e07a1"
integrity sha512-JK5uhiVyMqHiAJbgBa8rCvpP8bEhAE9dKDv1gCmP+EUP2FSPmEeW3WXlCXauPB3MDa8behPW+ntyNXqnGaxslg==
dependencies:
esbuild "^0.12.17"
postcss "^8.3.6"
......
......@@ -71,6 +71,8 @@ declare namespace UniApp {
onReady: (fn: Function) => void
serviceReady: boolean
locale: string
fallbackLocale: string
locales: Record<string, Record<string, string>>
}
interface UniRoute {
......
......@@ -1443,14 +1443,27 @@ var serviceContext = (function (vue) {
this.watchers.splice(index, 1);
};
}
add(locale, message) {
if (this.messages[locale]) {
Object.assign(this.messages[locale], message);
add(locale, message, override = true) {
const curMessages = this.messages[locale];
if (curMessages) {
if (override) {
Object.assign(curMessages, message);
}
else {
Object.keys(message).forEach((key) => {
if (!hasOwn(curMessages, key)) {
curMessages[key] = message[key];
}
});
}
}
else {
this.messages[locale] = message;
}
}
f(message, values) {
return this.formater.interpolate(message, values).join('');
}
t(key, locale, values) {
let message = this.message;
if (typeof locale === 'string') {
......@@ -1489,6 +1502,7 @@ var serviceContext = (function (vue) {
// }
// return uni.getSystemInfoSync().language
// }
const i18nInstances = [];
function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_EN, watcher) {
// 兼容旧版本入参
if (typeof locale !== 'string') {
......@@ -1503,6 +1517,7 @@ var serviceContext = (function (vue) {
messages,
watcher,
});
i18nInstances.push(i18n);
let t = (key, values) => {
if (typeof getApp !== 'function') {
// app view
......@@ -1542,11 +1557,14 @@ var serviceContext = (function (vue) {
};
return {
i18n,
f(message, values) {
return i18n.f(message, values);
},
t(key, values) {
return t(key, values);
},
add(locale, message) {
return i18n.add(locale, message);
add(locale, message, override = true) {
return i18n.add(locale, message, override);
},
watch(fn) {
return i18n.watchLocale(fn);
......@@ -1555,7 +1573,10 @@ var serviceContext = (function (vue) {
return i18n.getLocale();
},
setLocale(newLocale) {
return i18n.setLocale(newLocale);
// 更新所有实例 locale
i18nInstances.forEach((ins) => {
ins.setLocale(newLocale);
});
},
};
}
......@@ -1602,97 +1623,97 @@ var serviceContext = (function (vue) {
const name = 'uni.app.';
const keys = ['quit'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Press back button again to exit']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Press back button again to exit']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Pulse otra vez para salir']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Pulse otra vez para salir']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"Appuyez à nouveau pour quitter l'application",
]));
]), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['再按一次退出应用']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['再按一次退出应用']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['再按一次退出應用']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['再按一次退出應用']), false);
}
});
const initI18nShowActionSheetMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.showActionSheet.';
const keys = ['cancel'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler']));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler']), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消']), false);
}
});
const initI18nShowModalMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.showModal.';
const keys = ['cancel', 'confirm'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'OK']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'OK']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'OK']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'OK']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'OK']));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'OK']), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '确定']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '确定']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '確定']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '確定']), false);
}
});
const initI18nChooseImageMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.chooseImage.';
const keys = ['cancel', 'sourceType.album', 'sourceType.camera'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false);
}
});
const initI18nChooseVideoMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.chooseVideo.';
const keys = ['cancel', 'sourceType.album', 'sourceType.camera'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false);
}
});
const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
......@@ -1705,7 +1726,7 @@ var serviceContext = (function (vue) {
'Recognition failure',
'Tap to turn light on',
'Tap to turn light off',
]));
]), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
......@@ -1714,7 +1735,7 @@ var serviceContext = (function (vue) {
'Échec de la reconnaissance',
'Toque para encender la luz',
'Toque para apagar la luz',
]));
]), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
......@@ -1723,7 +1744,7 @@ var serviceContext = (function (vue) {
'Fallo de reconocimiento',
"Appuyez pour activer l'éclairage",
"Appuyez pour désactiver l'éclairage",
]));
]), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, [
......@@ -1732,7 +1753,7 @@ var serviceContext = (function (vue) {
'识别失败',
'轻触照亮',
'轻触关闭',
]));
]), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, [
......@@ -1741,28 +1762,28 @@ var serviceContext = (function (vue) {
'識別失敗',
'輕觸照亮',
'輕觸關閉',
]));
]), false);
}
});
const initI18nStartSoterAuthenticationMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.startSoterAuthentication.';
const keys = ['authContent'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Fingerprint recognition']));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Fingerprint recognition']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Reconocimiento de huellas dactilares']));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Reconocimiento de huellas dactilares']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"Reconnaissance de l'empreinte digitale",
]));
]), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['指纹识别中...']));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['指纹识别中...']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['指紋識別中...']));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['指紋識別中...']), false);
}
});
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -4,7 +4,7 @@ import { ConfigEnv } from 'vite'
import { extend, isArray, isString } from '@vue/shared'
interface ProjectFeatures {
i18nLocales: boolean
i18nLocale: boolean
i18nEn: boolean
i18nEs: boolean
i18nFr: boolean
......@@ -38,7 +38,7 @@ interface ManifestFeatures {
function initProjectFeature({ inputDir }: InitFeaturesOptions) {
const features: ProjectFeatures = {
i18nLocales: false,
i18nLocale: false,
i18nEn: true,
i18nEs: true,
i18nFr: true,
......@@ -50,7 +50,7 @@ function initProjectFeature({ inputDir }: InitFeaturesOptions) {
if (
fs.readdirSync(localesDir).find((file) => path.extname(file) === '.json')
) {
features.i18nLocales = true
features.i18nLocale = true
}
}
return features
......@@ -212,7 +212,7 @@ export function initFeatures(options: InitFeaturesOptions) {
i18nFr,
i18nZhHans,
i18nZhHant,
i18nLocales,
i18nLocale,
vueOptionsApi,
vueProdDevTools,
pages,
......@@ -250,7 +250,7 @@ export function initFeatures(options: InitFeaturesOptions) {
__UNI_FEATURE_I18N_ZH_HANS__: i18nZhHans, // 是否启用zh_Hans
__UNI_FEATURE_I18N_ZH_HANT__: i18nZhHant, // 是否启用zh_Hant
// 以下特性,编译器已自动识别是否需要启用
__UNI_FEATURE_I18N_LOCALES__: i18nLocales, // 是否启用i18n
__UNI_FEATURE_I18N_LOCALE__: i18nLocale, // 是否启用i18n
__UNI_FEATURE_NVUE__: nvue, // 是否启用nvue
__UNI_FEATURE_ROUTER_MODE__: routerMode, // 路由模式
__UNI_FEATURE_PAGES__: pages, // 是否多页面
......
......@@ -22,13 +22,15 @@ export const initI18nAppMsgsOnce = /*#__PURE__*/ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Press back button again to exit'])
normalizeMessages(name, keys, ['Press back button again to exit']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Pulse otra vez para salir'])
normalizeMessages(name, keys, ['Pulse otra vez para salir']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -36,19 +38,22 @@ export const initI18nAppMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_FR,
normalizeMessages(name, keys, [
"Appuyez à nouveau pour quitter l'application",
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['再按一次退出应用'])
normalizeMessages(name, keys, ['再按一次退出应用']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['再按一次退出應用'])
normalizeMessages(name, keys, ['再按一次退出應用']),
false
)
}
})
......@@ -60,7 +65,8 @@ export const initI18nAsyncMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_EN,
normalizeMessages(name, keys, [
'The connection timed out, click the screen to try again.',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
......@@ -68,7 +74,8 @@ export const initI18nAsyncMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ES,
normalizeMessages(name, keys, [
'Se agotó el tiempo de conexión, haga clic en la pantalla para volver a intentarlo.',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -76,19 +83,22 @@ export const initI18nAsyncMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_FR,
normalizeMessages(name, keys, [
"La connexion a expiré, cliquez sur l'écran pour réessayer.",
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['连接服务器超时,点击屏幕重试'])
normalizeMessages(name, keys, ['连接服务器超时,点击屏幕重试']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['連接服務器超時,點擊屏幕重試'])
normalizeMessages(name, keys, ['連接服務器超時,點擊屏幕重試']),
false
)
}
})
......@@ -96,19 +106,27 @@ export const initI18nShowActionSheetMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.showActionSheet.'
const keys = ['cancel']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel']))
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel']), false)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar']))
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar']), false)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler']))
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler']), false)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消']))
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['取消']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消']))
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['取消']),
false
)
}
})
export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
......@@ -119,7 +137,8 @@ export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_EN,
normalizeMessages(name, keys, [
'Please note showToast must be paired with hideToast',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
......@@ -127,7 +146,8 @@ export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ES,
normalizeMessages(name, keys, [
'Tenga en cuenta que showToast debe estar emparejado con hideToast',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -135,7 +155,8 @@ export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_FR,
normalizeMessages(name, keys, [
'Veuillez noter que showToast doit être associé à hideToast',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
......@@ -143,7 +164,8 @@ export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ZH_HANS,
normalizeMessages(name, keys, [
'请注意 showToast 与 hideToast 必须配对使用',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
......@@ -151,7 +173,8 @@ export const initI18nShowToastMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ZH_HANT,
normalizeMessages(name, keys, [
'請注意 showToast 與 hideToast 必須配對使用',
])
]),
false
)
}
})
......@@ -163,7 +186,8 @@ export const initI18nShowLoadingMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_EN,
normalizeMessages(name, keys, [
'Please note showLoading must be paired with hideLoading',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
......@@ -171,7 +195,8 @@ export const initI18nShowLoadingMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ES,
normalizeMessages(name, keys, [
'Tenga en cuenta que showLoading debe estar emparejado con hideLoading',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -179,7 +204,8 @@ export const initI18nShowLoadingMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_FR,
normalizeMessages(name, keys, [
'Veuillez noter que showLoading doit être associé à hideLoading',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
......@@ -187,7 +213,8 @@ export const initI18nShowLoadingMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ZH_HANS,
normalizeMessages(name, keys, [
'请注意 showLoading 与 hideLoading 必须配对使用',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
......@@ -195,7 +222,8 @@ export const initI18nShowLoadingMsgsOnce = /*#__PURE__*/ once(() => {
LOCALE_ZH_HANT,
normalizeMessages(name, keys, [
'請注意 showLoading 與 hideLoading 必須配對使用',
])
]),
false
)
}
})
......@@ -203,24 +231,38 @@ export const initI18nShowModalMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.showModal.'
const keys = ['cancel', 'confirm']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'OK']))
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Cancel', 'OK']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'OK']))
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Cancelar', 'OK']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'OK']))
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Annuler', 'OK']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['取消', '确定'])
normalizeMessages(name, keys, ['取消', '确定']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['取消', '確定'])
normalizeMessages(name, keys, ['取消', '確定']),
false
)
}
})
......@@ -230,31 +272,36 @@ export const initI18nChooseImageMsgsOnce = /*#__PURE__*/ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera'])
normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara'])
normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra'])
normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄'])
normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝'])
normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']),
false
)
}
})
......@@ -264,31 +311,36 @@ export const initI18nChooseVideoMsgsOnce = /*#__PURE__*/ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera'])
normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara'])
normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra'])
normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄'])
normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝'])
normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']),
false
)
}
})
......@@ -303,7 +355,8 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
'Save Image',
'Saved successfully',
'Save failed',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
......@@ -314,7 +367,8 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
'Guardar imagen',
'Guardado exitosamente',
'Error al guardar',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -325,7 +379,8 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
'Guardar imagen',
'Enregistré avec succès',
'Échec de la sauvegarde',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
......@@ -336,7 +391,8 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
'保存图像',
'保存图像到相册成功',
'保存图像到相册失败',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
......@@ -347,7 +403,8 @@ export const initI18nPreviewImageMsgsOnce = /*#__PURE__*/ once(() => {
'保存圖像',
'保存圖像到相冊成功',
'保存圖像到相冊失敗',
])
]),
false
)
}
})
......@@ -355,22 +412,39 @@ export const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.setClipboardData.'
const keys = ['success']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Content copied']))
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Content copied']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Contenido copiado'])
normalizeMessages(name, keys, ['Contenido copiado']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Contenu copié']))
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Contenu copié']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['内容已复制']))
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['内容已复制']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['內容已復制']))
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['內容已復制']),
false
)
}
})
export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
......@@ -385,7 +459,8 @@ export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
'Recognition failure',
'Tap to turn light on',
'Tap to turn light off',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
......@@ -397,7 +472,8 @@ export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
'Échec de la reconnaissance',
'Toque para encender la luz',
'Toque para apagar la luz',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -409,7 +485,8 @@ export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
'Fallo de reconocimiento',
"Appuyez pour activer l'éclairage",
"Appuyez pour désactiver l'éclairage",
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
......@@ -421,7 +498,8 @@ export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
'识别失败',
'轻触照亮',
'轻触关闭',
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
......@@ -433,7 +511,8 @@ export const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
'識別失敗',
'輕觸照亮',
'輕觸關閉',
])
]),
false
)
}
})
......@@ -444,13 +523,15 @@ export const initI18nStartSoterAuthenticationMsgsOnce = /*#__PURE__*/ once(
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Fingerprint recognition'])
normalizeMessages(name, keys, ['Fingerprint recognition']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Reconocimiento de huellas dactilares'])
normalizeMessages(name, keys, ['Reconocimiento de huellas dactilares']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
......@@ -458,19 +539,22 @@ export const initI18nStartSoterAuthenticationMsgsOnce = /*#__PURE__*/ once(
LOCALE_FR,
normalizeMessages(name, keys, [
"Reconnaissance de l'empreinte digitale",
])
]),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['指纹识别中...'])
normalizeMessages(name, keys, ['指纹识别中...']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['指紋識別中...'])
normalizeMessages(name, keys, ['指紋識別中...']),
false
)
}
}
......@@ -479,24 +563,38 @@ export const initI18nPickerMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.picker.'
const keys = ['done', 'cancel']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Done', 'Cancel']))
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Done', 'Cancel']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['OK', 'Cancelar']))
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['OK', 'Cancelar']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['OK', 'Annuler']))
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['OK', 'Annuler']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['完成', '取消'])
normalizeMessages(name, keys, ['完成', '取消']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['完成', '取消'])
normalizeMessages(name, keys, ['完成', '取消']),
false
)
}
})
......@@ -504,30 +602,38 @@ export const initI18nVideoMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.video.'
const keys = ['danmu', 'volume']
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Danmu', 'Volume']))
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['Danmu', 'Volume']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['Danmu', 'Volumen'])
normalizeMessages(name, keys, ['Danmu', 'Volumen']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ['Danmu', 'Le Volume'])
normalizeMessages(name, keys, ['Danmu', 'Le Volume']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['弹幕', '音量'])
normalizeMessages(name, keys, ['弹幕', '音量']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['彈幕', '音量'])
normalizeMessages(name, keys, ['彈幕', '音量']),
false
)
}
})
......@@ -537,31 +643,36 @@ export const initI18nButtonMsgsOnce = /*#__PURE__*/ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(
LOCALE_EN,
normalizeMessages(name, keys, ['feedback', 'send'])
normalizeMessages(name, keys, ['feedback', 'send']),
false
)
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(
LOCALE_ES,
normalizeMessages(name, keys, ['realimentación', 'enviar'])
normalizeMessages(name, keys, ['realimentación', 'enviar']),
false
)
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(
LOCALE_FR,
normalizeMessages(name, keys, ["retour d'information", 'envoyer'])
normalizeMessages(name, keys, ["retour d'information", 'envoyer']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(
LOCALE_ZH_HANS,
normalizeMessages(name, keys, ['问题反馈', '发送'])
normalizeMessages(name, keys, ['问题反馈', '发送']),
false
)
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(
LOCALE_ZH_HANT,
normalizeMessages(name, keys, ['問題反饋', '發送'])
normalizeMessages(name, keys, ['問題反饋', '發送']),
false
)
}
})
import { getEnvLocale } from '@dcloudio/uni-shared'
import { BuiltInLocale, initVueI18n } from '@dcloudio/uni-i18n'
import { getEnvLocale, I18N_JSON_DELIMITERS } from '@dcloudio/uni-shared'
import { BuiltInLocale, initVueI18n, isI18nStr } from '@dcloudio/uni-i18n'
let i18n: ReturnType<typeof initVueI18n>
......@@ -7,6 +7,21 @@ interface webviewStyleWithLanguage extends PlusWebviewWebviewStyles {
locale: string
}
function getLocaleMessage() {
const locale = useI18n().getLocale()
const locales = __uniConfig.locales
return (
locales[locale] || locales[__uniConfig.fallbackLocale] || locales.en || {}
)
}
export function formatI18n(message: string) {
if (__uniConfig.locales && isI18nStr(message, I18N_JSON_DELIMITERS)) {
return useI18n().f(message, getLocaleMessage())
}
return message
}
export function useI18n() {
if (!i18n) {
let locale: BuiltInLocale
......
......@@ -4,13 +4,12 @@ import { ModuleGraph, Plugin } from 'vite'
import { extend } from '@vue/shared'
import {
initEasycomsOnce,
initFeatures,
normalizePath,
parseManifestJson,
parsePagesJson,
} from '@dcloudio/uni-cli-shared'
import { initFeatures } from '../../utils'
const debugHmr = debug('vite:uni:hmr')
async function invalidate(file: string, moduleGraph: ModuleGraph) {
......
......@@ -54,7 +54,7 @@ function generatePagesJsonCode(
return `
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent, setupWindow } from '@dcloudio/uni-h5'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent, useI18n, setupWindow } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue, locale } from '${manifestJsonPath}'
const locales = import.meta.globEager('./locale/*.json')
${importLayoutComponentsCode}
......@@ -65,6 +65,11 @@ ${defineLayoutComponentsCode}
${definePagesCode}
${uniRoutesCode}
${config.command === 'serve' ? hmrCode : ''}
const localeKeys = Object.keys(__uniConfig.locales)
if (localeKeys.length) {
const i18n = useI18n()
localeKeys.forEach(locale=>i18n.add(locale,__uniConfig.locales[locale]))
}
export {}
`
}
......
import fs from 'fs'
import path from 'path'
import { ConfigEnv, UserConfig } from 'vite'
import { extend, isArray, isString } from '@vue/shared'
import {
parsePagesJsonOnce,
parseManifestJsonOnce,
initFeatures,
} from '@dcloudio/uni-cli-shared'
import { isSsr, isSsrManifest } from './ssr'
interface ProjectFeatures {}
interface PagesFeatures {
nvue: boolean
pages: boolean
tabBar: boolean
tabBarMidButton: boolean
topWindow: boolean
leftWindow: boolean
rightWindow: boolean
navigationBar: boolean
pullDownRefresh: boolean
navigationBarButtons: boolean
navigationBarSearchInput: boolean
navigationBarTransparent: boolean
}
interface ManifestFeatures {
wx: boolean
wxs: boolean
rpx: boolean
promise: boolean
longpress: boolean
routerMode: '"hash"' | '"history"'
i18nEn: boolean
i18nEs: boolean
i18nFr: boolean
i18nZhHans: boolean
i18nZhHant: boolean
vueOptionsApi: boolean
vueProdDevTools: boolean
}
function initProjectFeature({ command }: InitFeaturesOptions) {
const features: ProjectFeatures = {}
if (command === 'build') {
}
return features
}
function initPagesFeature({
pagesJson,
command,
inputDir,
ssr,
}: InitFeaturesOptions): PagesFeatures {
const features: PagesFeatures = {
nvue: true,
pages: true,
tabBar: true,
tabBarMidButton: true,
topWindow: false,
leftWindow: false,
rightWindow: false,
navigationBar: true,
pullDownRefresh: false,
navigationBarButtons: true,
navigationBarSearchInput: true,
navigationBarTransparent: true,
}
const { tabBar, pages, topWindow, leftWindow, rightWindow, globalStyle } =
pagesJson
// ssr 时强制启用多页面(需要用到router)
if (!ssr && pages && pages.length === 1) {
features.pages = false
}
if (!(tabBar && tabBar.list && tabBar.list.length)) {
features.tabBar = false
features.tabBarMidButton = false
}
if (features.tabBar && !tabBar!.midButton) {
features.tabBarMidButton = false
}
if (topWindow && topWindow.path) {
features.topWindow = true
}
if (leftWindow && leftWindow.path) {
features.leftWindow = true
}
if (rightWindow && rightWindow.path) {
features.rightWindow = true
}
if (globalStyle.enablePullDownRefresh) {
features.pullDownRefresh = true
} else {
if (pages.find((page) => page.style && page.style.enablePullDownRefresh)) {
features.pullDownRefresh = true
}
}
if (command === 'build') {
if (
!pages.find((page) =>
fs.existsSync(path.resolve(inputDir, page.path + '.nvue'))
)
) {
features.nvue = false
}
let isNavigationCustom = false
if (globalStyle.navigationBar.style === 'custom') {
isNavigationCustom = true // 全局custom
if (pages.find((page) => page.style.navigationBar.style === 'default')) {
isNavigationCustom = false
}
} else {
// 所有页面均custom
if (pages.every((page) => page.style.navigationBar.style === 'custom')) {
isNavigationCustom = true
}
}
if (isNavigationCustom) {
features.navigationBar = false
features.navigationBarButtons = false
features.navigationBarSearchInput = false
features.navigationBarTransparent = false
} else {
if (
!pages.find(
(page) =>
isArray(page.style.navigationBar.buttons) &&
page.style.navigationBar.buttons.length
)
) {
features.navigationBarButtons = false
}
if (
!globalStyle.navigationBar.searchInput &&
!pages.find((page) => page.style.navigationBar.searchInput)
) {
features.navigationBarSearchInput = false
}
if (
globalStyle.navigationBar.type !== 'transparent' &&
!pages.find((page) => page.style.navigationBar.type === 'transparent')
) {
features.navigationBarTransparent = false
}
}
}
return features
}
function initManifestFeature({
manifestJson,
command,
platform,
}: InitFeaturesOptions): ManifestFeatures {
const features: ManifestFeatures = {
wx: false,
wxs: true,
rpx: true,
promise: false,
longpress: true,
routerMode: '"hash"',
i18nEn: true,
i18nEs: true,
i18nFr: true,
i18nZhHans: true,
i18nZhHant: true,
vueOptionsApi: true,
vueProdDevTools: false,
}
if (command === 'build') {
// TODO 需要预编译一遍?
features.wxs = true
features.longpress = true
}
if (
manifestJson.h5 &&
manifestJson.h5.router &&
manifestJson.h5.router.mode === 'history'
) {
features.routerMode = '"history"'
}
const platformJson = manifestJson[platform] || {}
const manifestFeatures = platformJson.features
if (manifestFeatures) {
const { i18n } = manifestFeatures
if (isArray(i18n)) {
if (!i18n.includes('en')) {
features.i18nEn = false
}
if (!i18n.includes('es')) {
features.i18nEs = false
}
if (!i18n.includes('fr')) {
features.i18nFr = false
}
if (!i18n.includes('zh-Hans')) {
features.i18nZhHans = false
}
if (!i18n.includes('zh-Hant')) {
features.i18nZhHant = false
}
}
}
// TODO other features
return features
}
export type FEATURE_DEFINES = ReturnType<typeof initFeatures>
interface InitFeaturesOptions {
pagesJson: UniApp.PagesJson
manifestJson: any
inputDir: string
platform: UniApp.PLATFORM
command: ConfigEnv['command']
ssr: boolean
}
export function initFeatures(options: InitFeaturesOptions) {
const {
wx,
wxs,
rpx,
nvue,
i18nEn,
i18nEs,
i18nFr,
i18nZhHans,
i18nZhHant,
vueOptionsApi,
vueProdDevTools,
pages,
tabBar,
tabBarMidButton,
promise,
longpress,
routerMode,
topWindow,
leftWindow,
rightWindow,
navigationBar,
pullDownRefresh,
navigationBarButtons,
navigationBarSearchInput,
navigationBarTransparent,
} = extend(
initManifestFeature(options),
initPagesFeature(options),
initProjectFeature(options)
)
const features = {
// vue
__VUE_OPTIONS_API__: vueOptionsApi, // enable/disable Options API support, default: true
__VUE_PROD_DEVTOOLS__: vueProdDevTools, // enable/disable devtools support in production, default: false
// uni
__UNI_FEATURE_WX__: wx, // 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
__UNI_FEATURE_WXS__: wxs, // 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig)
__UNI_FEATURE_RPX__: rpx, // 是否启用运行时 rpx 支持
__UNI_FEATURE_PROMISE__: promise, // 是否启用旧版本的 promise 支持(即返回[err,res]的格式),默认返回标准
__UNI_FEATURE_LONGPRESS__: longpress, // 是否启用longpress
__UNI_FEATURE_I18N_EN__: i18nEn, // 是否启用en
__UNI_FEATURE_I18N_ES__: i18nEs, // 是否启用es
__UNI_FEATURE_I18N_FR__: i18nFr, // 是否启用fr
__UNI_FEATURE_I18N_ZH_HANS__: i18nZhHans, // 是否启用zh_Hans
__UNI_FEATURE_I18N_ZH_HANT__: i18nZhHant, // 是否启用zh_Hant
// 以下特性,编译器已自动识别是否需要启用
__UNI_FEATURE_NVUE__: nvue, // 是否启用nvue
__UNI_FEATURE_ROUTER_MODE__: routerMode, // 路由模式
__UNI_FEATURE_PAGES__: pages, // 是否多页面
__UNI_FEATURE_TABBAR__: tabBar, // 是否包含tabBar
__UNI_FEATURE_TABBAR_MIDBUTTON__: tabBarMidButton, // 是否包含midButton
__UNI_FEATURE_TOPWINDOW__: topWindow, // 是否包含topWindow
__UNI_FEATURE_LEFTWINDOW__: leftWindow, // 是否包含leftWindow
__UNI_FEATURE_RIGHTWINDOW__: rightWindow, // 是否包含rightWindow
__UNI_FEATURE_RESPONSIVE__: topWindow || leftWindow || rightWindow, // 是否启用响应式
__UNI_FEATURE_NAVIGATIONBAR__: navigationBar, // 是否启用标题栏
__UNI_FEATURE_PULL_DOWN_REFRESH__: pullDownRefresh, // 是否启用下拉刷新
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__: navigationBarButtons, // 是否启用标题栏按钮
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__: navigationBarSearchInput, // 是否启用标题栏搜索框
__UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__: navigationBarTransparent, // 是否启用透明标题栏
}
// ssr nodejs features
if (options.ssr) {
Object.keys(features).forEach((name) => {
const value = features[name as keyof typeof features]
extend(globalThis, {
[name]: isString(value) ? JSON.parse(value) : value,
})
})
}
return features
}
export function createDefine(
command: ConfigEnv['command'],
config: UserConfig
......
......@@ -26,6 +26,7 @@ const BLACKLIST = [
'cssConstant',
'cssEnv',
'cssVar',
'useI18n',
]
export function genApiJson(code: string) {
......
......@@ -7,6 +7,17 @@ var uniI18n = require("@dcloudio/uni-i18n");
var shared = require("@vue/shared");
var vueRouter = require("vue-router");
let i18n;
function getLocaleMessage() {
const locale = useI18n().getLocale();
const locales = __uniConfig.locales;
return locales[locale] || locales[__uniConfig.fallbackLocale] || locales.en || {};
}
function formatI18n(message) {
if (__uniConfig.locales && uniI18n.isI18nStr(message, uniShared.I18N_JSON_DELIMITERS)) {
return useI18n().f(message, getLocaleMessage());
}
return message;
}
function useI18n() {
if (!i18n) {
let locale;
......@@ -33,61 +44,61 @@ const initI18nAsyncMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(uniI18n.LOCALE_EN, normalizeMessages(name, keys, [
"The connection timed out, click the screen to try again."
]));
]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(uniI18n.LOCALE_ES, normalizeMessages(name, keys, [
"Se agot\xF3 el tiempo de conexi\xF3n, haga clic en la pantalla para volver a intentarlo."
]));
]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(uniI18n.LOCALE_FR, normalizeMessages(name, keys, [
"La connexion a expir\xE9, cliquez sur l'\xE9cran pour r\xE9essayer."
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5"]));
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66"]));
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66"]), false);
}
});
const initI18nPickerMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
const name = "uni.picker.";
const keys = ["done", "cancel"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(uniI18n.LOCALE_EN, normalizeMessages(name, keys, ["Done", "Cancel"]));
useI18n().add(uniI18n.LOCALE_EN, normalizeMessages(name, keys, ["Done", "Cancel"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(uniI18n.LOCALE_ES, normalizeMessages(name, keys, ["OK", "Cancelar"]));
useI18n().add(uniI18n.LOCALE_ES, normalizeMessages(name, keys, ["OK", "Cancelar"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(uniI18n.LOCALE_FR, normalizeMessages(name, keys, ["OK", "Annuler"]));
useI18n().add(uniI18n.LOCALE_FR, normalizeMessages(name, keys, ["OK", "Annuler"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]));
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]));
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]), false);
}
});
const initI18nVideoMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
const name = "uni.video.";
const keys = ["danmu", "volume"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(uniI18n.LOCALE_EN, normalizeMessages(name, keys, ["Danmu", "Volume"]));
useI18n().add(uniI18n.LOCALE_EN, normalizeMessages(name, keys, ["Danmu", "Volume"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(uniI18n.LOCALE_ES, normalizeMessages(name, keys, ["Danmu", "Volumen"]));
useI18n().add(uniI18n.LOCALE_ES, normalizeMessages(name, keys, ["Danmu", "Volumen"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(uniI18n.LOCALE_FR, normalizeMessages(name, keys, ["Danmu", "Le Volume"]));
useI18n().add(uniI18n.LOCALE_FR, normalizeMessages(name, keys, ["Danmu", "Le Volume"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5F39\u5E55", "\u97F3\u91CF"]));
useI18n().add(uniI18n.LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5F39\u5E55", "\u97F3\u91CF"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5F48\u5E55", "\u97F3\u91CF"]));
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5F48\u5E55", "\u97F3\u91CF"]), false);
}
});
const E = function() {
......@@ -10332,6 +10343,11 @@ function createPageHeadTitleTextTsx({
titleText,
titleImage
}) {
if (__UNI_FEATURE_I18N_LOCALE__) {
if (!titleImage && titleText) {
titleText = formatI18n(titleText);
}
}
return vue.createVNode("div", {
"class": "uni-page-head-bd"
}, [vue.createVNode("div", {
......@@ -10768,4 +10784,5 @@ exports.setupApp = setupApp;
exports.setupPage = setupPage;
exports.setupWindow = setupWindow;
exports.uni = uni$1;
exports.useI18n = useI18n;
exports.useTabBar = useTabBar;
import { withModifiers, createVNode, getCurrentInstance, defineComponent, ref, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, createElementBlock, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { extend, isString, stringifyStyle, parseStringStyle, isPlainObject, isFunction, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
let i18n;
function getLocaleMessage() {
const locale = useI18n().getLocale();
const locales = __uniConfig.locales;
return locales[locale] || locales[__uniConfig.fallbackLocale] || locales.en || {};
}
function formatI18n(message) {
if (__uniConfig.locales && isI18nStr(message, I18N_JSON_DELIMITERS)) {
return useI18n().f(message, getLocaleMessage());
}
return message;
}
function useI18n() {
if (!i18n) {
let locale;
......@@ -30,42 +41,42 @@ const initI18nAsyncMsgsOnce = /* @__PURE__ */ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, [
"The connection timed out, click the screen to try again."
]));
]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
"Se agot\xF3 el tiempo de conexi\xF3n, haga clic en la pantalla para volver a intentarlo."
]));
]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"La connexion a expir\xE9, cliquez sur l'\xE9cran pour r\xE9essayer."
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5"]));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66"]));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u9023\u63A5\u670D\u52D9\u5668\u8D85\u6642\uFF0C\u9EDE\u64CA\u5C4F\u5E55\u91CD\u8A66"]), false);
}
});
const initI18nShowActionSheetMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.showActionSheet.";
const keys = ["cancel"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Cancel"]));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Cancel"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Cancelar"]));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Cancelar"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Annuler"]));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Annuler"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u53D6\u6D88"]));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u53D6\u6D88"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u53D6\u6D88"]));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u53D6\u6D88"]), false);
}
});
const initI18nShowToastMsgsOnce = /* @__PURE__ */ once(() => {
......@@ -74,27 +85,27 @@ const initI18nShowToastMsgsOnce = /* @__PURE__ */ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, [
"Please note showToast must be paired with hideToast"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
"Tenga en cuenta que showToast debe estar emparejado con hideToast"
]));
]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"Veuillez noter que showToast doit \xEAtre associ\xE9 \xE0 hideToast"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, [
"\u8BF7\u6CE8\u610F showToast \u4E0E hideToast \u5FC5\u987B\u914D\u5BF9\u4F7F\u7528"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, [
"\u8ACB\u6CE8\u610F showToast \u8207 hideToast \u5FC5\u9808\u914D\u5C0D\u4F7F\u7528"
]));
]), false);
}
});
const initI18nShowLoadingMsgsOnce = /* @__PURE__ */ once(() => {
......@@ -103,84 +114,84 @@ const initI18nShowLoadingMsgsOnce = /* @__PURE__ */ once(() => {
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, [
"Please note showLoading must be paired with hideLoading"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
"Tenga en cuenta que showLoading debe estar emparejado con hideLoading"
]));
]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"Veuillez noter que showLoading doit \xEAtre associ\xE9 \xE0 hideLoading"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, [
"\u8BF7\u6CE8\u610F showLoading \u4E0E hideLoading \u5FC5\u987B\u914D\u5BF9\u4F7F\u7528"
]));
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, [
"\u8ACB\u6CE8\u610F showLoading \u8207 hideLoading \u5FC5\u9808\u914D\u5C0D\u4F7F\u7528"
]));
]), false);
}
});
const initI18nShowModalMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.showModal.";
const keys = ["cancel", "confirm"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Cancel", "OK"]));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Cancel", "OK"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Cancelar", "OK"]));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Cancelar", "OK"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Annuler", "OK"]));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Annuler", "OK"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u53D6\u6D88", "\u786E\u5B9A"]));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u53D6\u6D88", "\u786E\u5B9A"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u53D6\u6D88", "\u78BA\u5B9A"]));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u53D6\u6D88", "\u78BA\u5B9A"]), false);
}
});
const initI18nPickerMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.picker.";
const keys = ["done", "cancel"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Done", "Cancel"]));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Done", "Cancel"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["OK", "Cancelar"]));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["OK", "Cancelar"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["OK", "Annuler"]));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["OK", "Annuler"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5B8C\u6210", "\u53D6\u6D88"]), false);
}
});
const initI18nVideoMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.video.";
const keys = ["danmu", "volume"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Danmu", "Volume"]));
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ["Danmu", "Volume"]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Danmu", "Volumen"]));
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ["Danmu", "Volumen"]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Danmu", "Le Volume"]));
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ["Danmu", "Le Volume"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5F39\u5E55", "\u97F3\u91CF"]));
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u5F39\u5E55", "\u97F3\u91CF"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5F48\u5E55", "\u97F3\u91CF"]));
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u5F48\u5E55", "\u97F3\u91CF"]), false);
}
});
const E = function() {
......@@ -20677,6 +20688,11 @@ function createPageHeadTitleTextTsx({
titleText,
titleImage
}) {
if (__UNI_FEATURE_I18N_LOCALE__) {
if (!titleImage && titleText) {
titleText = formatI18n(titleText);
}
}
return createVNode("div", {
"class": "uni-page-head-bd"
}, [createVNode("div", {
......@@ -21251,4 +21267,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
......@@ -9,6 +9,7 @@ import {
ICON_PATH_SEARCH,
ICON_PATH_BACK,
ICON_PATH_CLOSE,
formatI18n,
} from '@dcloudio/uni-core'
import { usePageMeta } from '../../setup/provide'
import {
......@@ -157,6 +158,11 @@ function createPageHeadTitleTextTsx({
titleText,
titleImage,
}: UniApp.PageNavigationBar) {
if (__UNI_FEATURE_I18N_LOCALE__) {
if (!titleImage && titleText) {
titleText = formatI18n(titleText)
}
}
return (
<div class="uni-page-head-bd">
<div
......
......@@ -29,6 +29,8 @@ export {
View,
} from '@dcloudio/uni-components'
export { useI18n } from '@dcloudio/uni-core'
export { default as plugin } from './framework/plugin'
export * from './framework/setup'
......
......@@ -183,14 +183,27 @@ class I18n {
this.watchers.splice(index, 1);
};
}
add(locale, message) {
if (this.messages[locale]) {
Object.assign(this.messages[locale], message);
add(locale, message, override = true) {
const curMessages = this.messages[locale];
if (curMessages) {
if (override) {
Object.assign(curMessages, message);
}
else {
Object.keys(message).forEach((key) => {
if (!hasOwn(curMessages, key)) {
curMessages[key] = message[key];
}
});
}
}
else {
this.messages[locale] = message;
}
}
f(message, values) {
return this.formater.interpolate(message, values).join('');
}
t(key, locale, values) {
let message = this.message;
if (typeof locale === 'string') {
......@@ -229,6 +242,7 @@ function initLocaleWatcher(appVm, i18n) {
// }
// return uni.getSystemInfoSync().language
// }
const i18nInstances = [];
function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_EN, watcher) {
// 兼容旧版本入参
if (typeof locale !== 'string') {
......@@ -243,6 +257,7 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
messages,
watcher,
});
i18nInstances.push(i18n);
let t = (key, values) => {
if (typeof getApp !== 'function') {
// app view
......@@ -282,11 +297,14 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
};
return {
i18n,
f(message, values) {
return i18n.f(message, values);
},
t(key, values) {
return t(key, values);
},
add(locale, message) {
return i18n.add(locale, message);
add(locale, message, override = true) {
return i18n.add(locale, message, override);
},
watch(fn) {
return i18n.watchLocale(fn);
......@@ -295,7 +313,10 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
return i18n.getLocale();
},
setLocale(newLocale) {
return i18n.setLocale(newLocale);
// 更新所有实例 locale
i18nInstances.forEach((ins) => {
ins.setLocale(newLocale);
});
},
};
}
......@@ -415,5 +436,6 @@ exports.LOCALE_ZH_HANT = LOCALE_ZH_HANT;
exports.compileI18nJsonStr = compileI18nJsonStr;
exports.hasI18nJson = hasI18nJson;
exports.initVueI18n = initVueI18n;
exports.isI18nStr = isI18nStr;
exports.isString = isString;
exports.parseI18nJson = parseI18nJson;
......@@ -31,7 +31,8 @@ export declare class I18n {
setLocale(locale: string): void;
getLocale(): BuiltInLocale;
watchLocale(fn: LocaleWatcher): () => void;
add(locale: BuiltInLocale, message: Record<string, string>): void;
add(locale: BuiltInLocale, message: Record<string, string>, override?: boolean): void;
f(message: string, values?: Record<string, unknown> | Array<unknown>): string;
t(key: string, values?: Record<string, unknown> | Array<unknown> | BuiltInLocale): string;
t(key: string, locale?: BuiltInLocale, values?: Record<string, unknown> | Array<unknown>): string;
}
......@@ -46,13 +47,16 @@ export declare interface I18nOptions {
export declare function initVueI18n(locale?: BuiltInLocale, messages?: LocaleMessages, fallbackLocale?: BuiltInLocale, watcher?: (locale: BuiltInLocale) => void): {
i18n: I18n;
f(message: string, values?: Record<string, unknown> | unknown[] | undefined): string;
t(key: string, values?: Record<string, unknown> | unknown[] | undefined): string;
add(locale: BuiltInLocale, message: Record<string, string>): void;
add(locale: BuiltInLocale, message: Record<string, string>, override?: boolean): void;
watch(fn: LocaleWatcher): () => void;
getLocale(): BuiltInLocale;
setLocale(newLocale: BuiltInLocale): void;
};
export declare function isI18nStr(value: string, delimiters: [string, string]): boolean;
export declare const isString: (val: unknown) => val is string;
export declare const LOCALE_EN = "en";
......
......@@ -179,14 +179,27 @@ class I18n {
this.watchers.splice(index, 1);
};
}
add(locale, message) {
if (this.messages[locale]) {
Object.assign(this.messages[locale], message);
add(locale, message, override = true) {
const curMessages = this.messages[locale];
if (curMessages) {
if (override) {
Object.assign(curMessages, message);
}
else {
Object.keys(message).forEach((key) => {
if (!hasOwn(curMessages, key)) {
curMessages[key] = message[key];
}
});
}
}
else {
this.messages[locale] = message;
}
}
f(message, values) {
return this.formater.interpolate(message, values).join('');
}
t(key, locale, values) {
let message = this.message;
if (typeof locale === 'string') {
......@@ -225,6 +238,7 @@ function initLocaleWatcher(appVm, i18n) {
// }
// return uni.getSystemInfoSync().language
// }
const i18nInstances = [];
function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_EN, watcher) {
// 兼容旧版本入参
if (typeof locale !== 'string') {
......@@ -239,6 +253,7 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
messages,
watcher,
});
i18nInstances.push(i18n);
let t = (key, values) => {
if (typeof getApp !== 'function') {
// app view
......@@ -278,11 +293,14 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
};
return {
i18n,
f(message, values) {
return i18n.f(message, values);
},
t(key, values) {
return t(key, values);
},
add(locale, message) {
return i18n.add(locale, message);
add(locale, message, override = true) {
return i18n.add(locale, message, override);
},
watch(fn) {
return i18n.watchLocale(fn);
......@@ -291,7 +309,10 @@ function initVueI18n(locale = LOCALE_EN, messages = {}, fallbackLocale = LOCALE_
return i18n.getLocale();
},
setLocale(newLocale) {
return i18n.setLocale(newLocale);
// 更新所有实例 locale
i18nInstances.forEach((ins) => {
ins.setLocale(newLocale);
});
},
};
}
......@@ -401,4 +422,4 @@ function walkJsonObj(jsonObj, walk) {
return false;
}
export { BaseFormatter as Formatter, I18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT, compileI18nJsonStr, hasI18nJson, initVueI18n, isString, parseI18nJson };
export { BaseFormatter as Formatter, I18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT, compileI18nJsonStr, hasI18nJson, initVueI18n, isI18nStr, isString, parseI18nJson };
......@@ -130,13 +130,29 @@ export class I18n {
this.watchers.splice(index, 1)
}
}
add(locale: BuiltInLocale, message: Record<string, string>) {
if (this.messages[locale]) {
Object.assign(this.messages[locale], message)
add(
locale: BuiltInLocale,
message: Record<string, string>,
override: boolean = true
) {
const curMessages = this.messages[locale]
if (curMessages) {
if (override) {
Object.assign(curMessages, message)
} else {
Object.keys(message).forEach((key) => {
if (!hasOwn(curMessages, key)) {
curMessages[key] = message[key]
}
})
}
} else {
this.messages[locale] = message
}
}
f(message: string, values?: Record<string, unknown> | Array<unknown>) {
return this.formater.interpolate(message, values).join('')
}
t(
key: string,
values?: Record<string, unknown> | Array<unknown> | BuiltInLocale
......
......@@ -93,7 +93,7 @@ export function compileI18nJsonStr(
return jsonStr
}
function isI18nStr(value: string, delimiters: [string, string]) {
export function isI18nStr(value: string, delimiters: [string, string]) {
return value.indexOf(delimiters[0]) > -1
}
......
......@@ -39,6 +39,8 @@ function initLocaleWatcher(appVm: any, i18n: I18n) {
// return uni.getSystemInfoSync().language
// }
const i18nInstances: I18n[] = []
export function initVueI18n(
locale: BuiltInLocale = LOCALE_EN,
messages: LocaleMessages = {},
......@@ -58,6 +60,9 @@ export function initVueI18n(
messages,
watcher,
})
i18nInstances.push(i18n)
let t: Interpolate = (key, values) => {
if (typeof getApp !== 'function') {
// app view
......@@ -95,11 +100,18 @@ export function initVueI18n(
}
return {
i18n,
f(message: string, values?: Record<string, unknown> | Array<unknown>) {
return i18n.f(message, values)
},
t(key: string, values?: Record<string, unknown> | Array<unknown>) {
return t(key, values)
},
add(locale: BuiltInLocale, message: Record<string, string>) {
return i18n.add(locale, message)
add(
locale: BuiltInLocale,
message: Record<string, string>,
override: boolean = true
) {
return i18n.add(locale, message, override)
},
watch(fn: LocaleWatcher) {
return i18n.watchLocale(fn)
......@@ -108,7 +120,10 @@ export function initVueI18n(
return i18n.getLocale()
},
setLocale(newLocale: BuiltInLocale) {
return i18n.setLocale(newLocale)
// 更新所有实例 locale
i18nInstances.forEach((ins) => {
ins.setLocale(newLocale)
})
},
}
}
/// <reference types="css-font-loading-module" />
import { ComponentInternalInstance } from 'vue';
import { ComponentOptionsBase } from 'vue';
import { ComponentPublicInstance } from 'vue';
import { FontFaceDescriptors } from 'css-font-loading-module';
import { RendererNode } from 'vue';
export declare const ACTION_TYPE_ADD_EVENT = 8;
......
import { FontFaceDescriptors } from 'css-font-loading-module'
import { isString } from '@vue/shared'
import { getCustomDataset } from './customDataset'
export { initCustomDataset, getCustomDataset } from './customDataset'
......
......@@ -53,6 +53,7 @@ export function uniResolveIdPlugin(
path.join(id, BUILT_IN_MODULES[id as BuiltInModulesKey])
))
}
// fixed by vite 3.5.2 https://github.com/vitejs/vite/pull/4728
if (isInHBuilderX()) {
// 解决文件路径包含转义字符(空格)等
// /@fs/Applications/HBuilderX%20Alpha.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/client/env.mjs
......
......@@ -90,7 +90,7 @@ function generateI18nModuleLocaleCode(locale, messages) {
return ` if (__UNI_FEATURE_I18N_${locale}__) {
useI18n().add(LOCALE_${locale}, normalizeMessages(name, keys, ${JSON.stringify(
messages
)}))
)}), false)
}
`
}
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册