From d086af1b70d31f4155a9febc2fac505b481ee579 Mon Sep 17 00:00:00 2001 From: handongxun Date: Fri, 6 Aug 2021 15:06:05 +0800 Subject: [PATCH] feat(i18n):impl --- packages/uni-cli-i18n/lib/index.js | 2 +- packages/uni-cli-i18n/locales/en.json | 67 ++++++++++++++++++- packages/uni-cli-i18n/locales/zh_CN.json | 67 ++++++++++++++++++- packages/uni-cli-shared/lib/json.js | 17 ++--- packages/uni-cli-shared/lib/package.js | 10 +-- packages/uni-cli-shared/lib/pages.js | 11 ++- packages/uni-cli-shared/lib/plugin.js | 16 ++--- packages/uni-migration/lib/index.js | 4 +- packages/uni-migration/lib/validate.js | 10 +-- packages/uni-mp-weixin/lib/uni.compiler.js | 8 +-- packages/uni-stat/src/parameter.js | 15 +++-- packages/uni-template-compiler/lib/mp.js | 6 +- .../lib/script/traverse/data/class.js | 3 +- .../lib/script/traverse/visitor.js | 3 +- .../lib/template/generate.js | 3 +- .../lib/template/traverse.js | 3 +- packages/uni-template-compiler/lib/util.js | 3 +- packages/vue-cli-plugin-hbuilderx/index.js | 5 +- .../packages/webpack-app-plus-plugin/index.js | 9 +-- .../webpack-uni-nvue-loader/lib/style.js | 5 +- .../template/bin/uniapp-cli.js | 7 +- packages/vue-cli-plugin-uni/commands/build.js | 10 +-- .../vue-cli-plugin-uni/lib/commands/custom.js | 5 +- .../vue-cli-plugin-uni/lib/commands/invoke.js | 9 +-- packages/vue-cli-plugin-uni/lib/env.js | 37 +++++----- .../webpack-uni-app-loader/plugin/index.js | 5 +- .../lib/babel-plugin-global-component.js | 8 ++- .../lib/babel-plugin-scoped-component.js | 6 +- .../lib/babel/global-component-traverse.js | 8 ++- .../webpack-uni-mp-loader/lib/babel/util.js | 9 +-- .../webpack-uni-mp-loader/lib/main-new.js | 6 +- .../webpack-uni-mp-loader/lib/script-new.js | 10 +-- .../webpack-uni-pages-loader/lib/index-new.js | 8 ++- .../lib/platforms/mp.js | 8 +-- 34 files changed, 280 insertions(+), 123 deletions(-) diff --git a/packages/uni-cli-i18n/lib/index.js b/packages/uni-cli-i18n/lib/index.js index 496e99a0d..c96220a04 100644 --- a/packages/uni-cli-i18n/lib/index.js +++ b/packages/uni-cli-i18n/lib/index.js @@ -1,7 +1,7 @@ const { I18n } = require('i18n') const { format } = require('./lang') -const defaultLocale = format(process.env.UNI_HBUILDERX_LANGID || process.env.LANG) +const defaultLocale = format(process.env.UNI_HBUILDERX_LANGID || process.env.LANG || 'en') const i18n = new I18n() diff --git a/packages/uni-cli-i18n/locales/en.json b/packages/uni-cli-i18n/locales/en.json index 9e26dfeeb..9c57bdb6e 100644 --- a/packages/uni-cli-i18n/locales/en.json +++ b/packages/uni-cli-i18n/locales/en.json @@ -1 +1,66 @@ -{} \ No newline at end of file +{ + "warning": "Warning⚠", + "syntaxError": "Syntax Error❌", + "compilerVersion": "Compiler version", + "compiling": "Compiling...", + "see": "see", + "performingHotReload": "Performing hot reload...", + "cliShared.parsingFailed": "Parsing failed", + "cliShared.doesNotExist": "does not exist", + "cliShared.pagesJsonError": "pages.json page configuration error, has been ignored, see {{0}}", + "cliShared.requireReturnJsonObject": "require return a json object", + "cliShared.requireExportFunction": "Function must be exported", + "cliShared.easycomConflict": "easycom component conflict:", + "cliShared.noFoundPlatformPlugin": "Missing platform {{0}} plugin", + "cliShared.extendOnlySupportH5": "Currently only supports expansion based on the h5 platform", + "cliShared.supportPlatform": "{{0}} support the following platforms {{1}}", + "cliShared.requireConfigUniPlatform": "{{0}} does not exist, you must configure the env->UNI_PLATFORM base platform", + "cliShared.missingNameAttribute": "{{0}} missing name property", + "cliShared.missingUniConfig": "{{0}} missing uni.config.js", + "migration.errorOnlySupportConvert": "Error: {{0}} conversion is currently supported", + "migration.errorInputNotExists": "Error: '{{0}}' not exist", + "migration.errorCannotConvert": "Error: '{{0}}' does not support conversion", + "migration.errorConvertRequireFileUrl": "Error: Single file conversion requires {{0}} file url", + "mpWeChat.onlySupportDestructuringSlot": "Currently only supports destructuring slot {{0}}, such as {{1}}", + "mpWeChat.slotPropNoSupportReanme": "Deconstructing the slot Prop, does not support renaming {{0}} to {{1}}, the performance will be affected after renaming", + "uniStat.missingParameter": "Missing [eventName] parameter", + "uniStat.parameterLengthLess": "Parameter length cannot be greater than", + "uniStat.parameterTypeErrrorString": "Parameter type error, it can only be of type String", + "uniStat.parameterTypeErrrorStringOrObject": "Parameter type error, Only supports String or Object type", + "uniStat.hasTitleOptionString": "When the parameter is title, the [options] parameter can only be of type String", + "templateCompiler.noH5KeyNoSupportExpression": "Non-h5 platforms: key does not support expression {{0}}, for details, please refer to: {{1}}", + "templateCompiler.notCurrentlySupportScopedSlot": "Not currently supported scoped slot {{0}}", + "templateCompiler.idAttribNotAllowInCustomComponentProps": "id is reserved as a property name and is not allowed to be defined as props in custom component {{0}}", + "templateCompiler.notSupportDynamicSlotName": "{{0}} Does not support dynamic slot names", + "templateCompiler.forNestedIndexNameNoArrowRepeat": "{{0}} When v-for is nested, the index name {{1}} is not allowed to be repeated", + "templateCompiler.noSupportSyntax": "Does not support {{0}} syntax", + "pluginHbuilderx.plaseHXCompileAppPlatform": "Please use HBuilderX to compile and run to the app-plus platform", + "pluginHbuilderx.hxBuildFailed": "Build failed: HBuilderX installation directory cannot include special characters such as {{0}}", + "pluginHbuilderx.nvueCssWarning": "The following css is not supported in nvue. If the global or public style is affected, it is recommended to write the warning style in the conditional compilation of ifndef APP-PLUS-NVUE. The details are as follows:", + "pluginUni.runDebugMode": "Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.", + "pluginUni.runDebugModeNvue": "Especially the sourcemap of app-nvue has a greater impact", + "pluginUni.runDebugModeMP": "To officially release, please click the release menu or use the cli release command to release", + "pluginUni.compileToMpPluginOnlySupportWeChat": "Compile to mini-program plug-in only supports WeChat mini-program", + "pluginUni.startCompileProjectToPlatform": "Start to compile the current project to the {{0}} platform...", + "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} file does not exist, please check and try again", + "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} The entry file does not exist, please check and try again", + "pluginUni.nvueCompileModeForDetail": "Current NVUE compile mode {{0}}. see: {{1}}", + "pluginUni.currentProjectDefaultSpaceId": "The default service space spaceId used by uniCloud of the current project is: {{0}}", + "pluginUni.unicloudReleaseH5": "To release H5, you need to operate on the uniCloud web console and bind a secure domain name, otherwise it will be inaccessible due to cross-domain issues. Tutorial reference:{{0}}", + "pluginUni.unicloudShowedRunByHBuilderX": "The current project uses uniCloud. In order to avoid the cross-domain problem of cloud function calls, it is recommended to debug in the HBuilderX built-in browser. If you use an external browser, you need to handle cross-domain. See details: {{0}}", + "pluginUni.pleaseSpecifyPluginName": "Please specify the plugin name", + "pluginUni.pluginNameNotExist": "Plug-in name does not exist", + "pluginUni.pluginIllegal": "The plugin is illegal", + "pluginUni.uniStatisticsNoAppid": "The current application is not configured with Appid, and uni statistics cannot be used. For details, see {{0}}", + "pluginUni.pleaseConfigScriptName": "Please specify the script name under package.json->uni-app->scripts", + "pluginUni.mpBrowserKernelDifference": "There are differences in the implementation mechanism of the browser kernels and custom components of each mini-program, and there may be compatibility issues with styles and layouts, please refer to:", + "mpLoader.firstParameterNeedStaticString": "The first parameter of {{0}} must be a static string", + "mpLoader.requireTwoParameter": "{{0}} requires two parameters", + "mpLoader.findFail": "{{0}} find fail", + "mpLoader.componentReferenceError": "Component {{0}} reference error", + "mpLoader.componentReferenceErrorOnlySupportImport": "Component {{0}} reference error, only supports import components", + "pagesLoader.pagesNodeCannotNull": "Pages node in pages.json cannot be empty", + "pagesLoader.nvueFirstPageStartModeIsFast": "Nvue homepage startup mode: fast. For details, see: {{0}}", + "pagesLoader.pagesTabbarMinItem2": "{{0}} must contain at least 2 items", + "pagesLoader.needInPagesNode": "{{0}} needs to be in the pages array" +} \ No newline at end of file diff --git a/packages/uni-cli-i18n/locales/zh_CN.json b/packages/uni-cli-i18n/locales/zh_CN.json index 9e26dfeeb..df9050fb4 100644 --- a/packages/uni-cli-i18n/locales/zh_CN.json +++ b/packages/uni-cli-i18n/locales/zh_CN.json @@ -1 +1,66 @@ -{} \ No newline at end of file +{ + "warning": "警告⚠", + "syntaxError": "语法错误❌", + "compilerVersion": "编译器版本", + "compiling": "正在编译中...", + "see": "看", + "performingHotReload": "正在热重载...", + "cliShared.parsingFailed": "解析失败", + "cliShared.doesNotExist": "不存在", + "cliShared.pagesJsonError": "pages.json 页面配置错误,已被忽略,查看文档: {{0}}", + "cliShared.requireReturnJsonObject": "必须返回一个 json 对象", + "cliShared.requireExportFunction": "必须导出 function", + "cliShared.easycomConflict": "easycom组件冲突:{{0}}", + "cliShared.noFoundPlatformPlugin": "缺少平台 {{0}} 插件", + "cliShared.extendOnlySupportH5": "目前仅支持基于 h5 平台做扩展", + "cliShared.supportPlatform": "{{0}} 支持以下平台 {{1}}", + "cliShared.requireConfigUniPlatform": "{{0}} 不存在,必须配置 env->UNI_PLATFORM 基础平台", + "cliShared.missingNameAttribute": "{{0}} 缺少 name 属性", + "cliShared.missingUniConfig": "{{0}} 缺少 uni.config.js", + "migration.errorOnlySupportConvert": "错误: 目前支持 {{0}} 转换", + "migration.errorInputNotExists": "错误: '{{0}}' 不存在", + "migration.errorCannotConvert": "错误: '{{0}}' 不支持转换", + "migration.errorConvertRequireFileUrl": "错误: 单文件转换需要传入 {{0}} 文件地址", + "mpWeChat.onlySupportDestructuringSlot": "目前仅支持解构插槽 {{0}},如 {{1}}", + "mpWeChat.slotPropNoSupportReanme": "解构插槽 Prop,不支持将 {{0}} 重命名为 {{1}},重命名后会影响性能", + "uniStat.missingParameter": "缺少 [eventName] 参数", + "uniStat.parameterLengthLess": "参数长度不能大于", + "uniStat.parameterTypeErrrorString": "参数类型错误,只能为 String 类型", + "uniStat.parameterTypeErrrorStringOrObject": "参数类型错误,只能为 String 或 Object 类型", + "uniStat.hasTitleOptionString": "参数为 title 时,[options] 参数只能为 String 类型", + "templateCompiler.noH5KeyNoSupportExpression": "非 h5 平台 :key 不支持表达式 {{0}},详情参考: {{1}}", + "templateCompiler.notCurrentlySupportScopedSlot": "暂不支持 scoped slot {{0}}", + "templateCompiler.idAttribNotAllowInCustomComponentProps": "id 作为属性保留名,不允许在自定义组件 {{0}} 中定义为 props", + "templateCompiler.notSupportDynamicSlotName": "{{0}} 不支持动态插槽名", + "templateCompiler.forNestedIndexNameNoArrowRepeat": "{{0}} v-for 嵌套时,索引名称 {{1}} 不允许重复", + "templateCompiler.noSupportSyntax": "不支持 {{0}} 语法", + "pluginHbuilderx.plaseHXCompileAppPlatform": "请使用 HBuilderX 编译运行至 app-plus 平台", + "pluginHbuilderx.hxBuildFailed": "编译失败:HBuilderX 安装目录不能包括 {{0}} 等特殊字符", + "pluginHbuilderx.nvueCssWarning": "nvue中不支持如下css。如全局或公共样式受影响,建议将告警样式写在ifndef APP-PLUS-NVUE的条件编译中,详情如下:", + "pluginUni.runDebugMode": "请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。", + "pluginUni.runDebugModeNvue": "尤其是app-nvue的sourcemap影响较大", + "pluginUni.runDebugModeMP": "若要正式发布,请点击发行菜单或使用cli发布命令进行发布", + "pluginUni.compileToMpPluginOnlySupportWeChat": "编译到小程序插件只支持微信小程序", + "pluginUni.startCompileProjectToPlatform": "开始编译当前项目至 {{0}} 平台...", + "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} 文件不存在,请检查后重试", + "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} 入口文件不存在,请检查后重试", + "pluginUni.nvueCompileModeForDetail": "当前nvue编译模式:{{0}}。编译模式差异见 {{1}}", + "pluginUni.currentProjectDefaultSpaceId": "当前项目的uniCloud使用的默认服务空间spaceId为:{{0}}", + "pluginUni.unicloudReleaseH5": "发布H5,需要在uniCloud web控制台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:{{0}}", + "pluginUni.unicloudShowedRunByHBuilderX": "当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:{{0}}", + "pluginUni.pleaseSpecifyPluginName": "请指定插件名", + "pluginUni.pluginNameNotExist": "插件名称不存在", + "pluginUni.pluginIllegal": "插件不合法", + "pluginUni.uniStatisticsNoAppid": "当前应用未配置Appid,无法使用uni统计,详情参考 {{0}}", + "pluginUni.pleaseConfigScriptName": "请指定 package.json->uni-app->scripts 下的 script 名称", + "pluginUni.mpBrowserKernelDifference": "小程序各家浏览器内核及自定义组件实现机制存在差异,可能存在样式布局兼容问题,参考:", + "mpLoader.firstParameterNeedStaticString": "{{0}}的第一个参数必须为静态字符串", + "mpLoader.requireTwoParameter": "{{0}}需要两个参数", + "mpLoader.findFail": "{{0}}查找失败", + "mpLoader.componentReferenceError": "组件 {{0}} 引用错误", + "mpLoader.componentReferenceErrorOnlySupportImport": "组件 {{0}} 引用错误,仅支持 import 方式引入组件", + "pagesLoader.pagesNodeCannotNull": "pages.json 中的 pages 节点不能为空", + "pagesLoader.nvueFirstPageStartModeIsFast": "Nvue 首页启动模式: fast, 详见: {{0}}", + "pagesLoader.pagesTabbarMinItem2": "{{0}} 需至少包含2项", + "pagesLoader.needInPagesNode": "{{0}} 需在 pages 数组中" +} \ No newline at end of file diff --git a/packages/uni-cli-shared/lib/json.js b/packages/uni-cli-shared/lib/json.js index b2db2beea..810173e88 100644 --- a/packages/uni-cli-shared/lib/json.js +++ b/packages/uni-cli-shared/lib/json.js @@ -1,6 +1,7 @@ const fs = require('fs') const path = require('path') const stripJsonComments = require('strip-json-comments') +const uniI18n = require('@dcloudio/uni-cli-i18n') function parseJson (content, preprocess = false) { if (typeof content === 'string') { @@ -13,11 +14,11 @@ function parseJson (content, preprocess = false) { type: jsPreprocessOptions.type }) } - - try { - content = JSON.parse(stripJsonComments(content)) - } catch (e) { - throw new Error('uni-app-compiler: ' + e.message) + + try { + content = JSON.parse(stripJsonComments(content)) + } catch (e) { + throw new Error('uni-app-compiler: ' + e.message) } } @@ -31,16 +32,16 @@ function parseJson (content, preprocess = false) { function getJson (jsonFileName, preprocess = false) { const jsonFilePath = path.resolve(process.env.UNI_INPUT_DIR, jsonFileName) if (!fs.existsSync(jsonFilePath)) { - throw new Error(jsonFilePath + ' 不存在') + throw new Error(jsonFilePath + ' ' + uniI18n.__('cliShared.doesNotExist')) } try { return parseJson(fs.readFileSync(jsonFilePath, 'utf8'), preprocess) } catch (e) { - console.error(jsonFileName + ' 解析失败') + console.error(jsonFileName + uniI18n.__('cliShared.parsingFailed')) } } module.exports = { getJson, parseJson -} +} diff --git a/packages/uni-cli-shared/lib/package.js b/packages/uni-cli-shared/lib/package.js index 4a5fc5e36..8526df658 100644 --- a/packages/uni-cli-shared/lib/package.js +++ b/packages/uni-cli-shared/lib/package.js @@ -1,3 +1,5 @@ +const uniI18n = require('@dcloudio/uni-cli-i18n') + const PLATFORMS = [ 'h5', 'app-plus', @@ -20,22 +22,22 @@ module.exports = { } if (!scriptOptions) { - console.error(`package.json->uni-app->scripts->${name} 不存在`) + console.error(`package.json->uni-app->scripts->${name} ${uniI18n.__('cliShared.doesNotExist')}`) process.exit(0) } if (!scriptOptions.env || !scriptOptions.env.UNI_PLATFORM) { - console.error(`package.json->uni-app->scripts->${name}->env 不存在,必须配置 env->UNI_PLATFORM 基础平台`) + console.error(uniI18n.__('cliShared.requireConfigUniPlatform', { "0": `package.json->uni-app->scripts->${name}->env ` })) process.exit(0) } if (PLATFORMS.indexOf(scriptOptions.env.UNI_PLATFORM) === -1) { - console.error(`UNI_PLATFORM 支持以下平台 ${JSON.stringify(PLATFORMS)}`) + console.error(uniI18n.__('cliShared.supportPlatform', { "0": 'UNI_PLATFORM', "1": JSON.stringify(PLATFORMS)})) process.exit(0) } process.env.UNI_PLATFORM = scriptOptions.env.UNI_PLATFORM - + process.env.UNI_SCRIPT = name process.UNI_SCRIPT_ENV = scriptOptions.env || {} process.UNI_SCRIPT_DEFINE = scriptOptions.define || {} diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js index d19f2d3f9..5eb3f5ff2 100644 --- a/packages/uni-cli-shared/lib/pages.js +++ b/packages/uni-cli-shared/lib/pages.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const uniI18n = require('@dcloudio/uni-cli-i18n') const { removeExt, @@ -62,10 +63,10 @@ function processPagesJson (pagesJson, loader = { if (typeof pagesJsonJsFn === 'function') { pagesJson = pagesJsonJsFn(pagesJson, loader) if (!pagesJson) { - console.error(`${pagesJsonJsFileName} 必须返回一个 json 对象`) + console.error(`${pagesJsonJsFileName} ${uniI18n.__('cliShared.requireReturnJsonObject')}`) } } else { - console.error(`${pagesJsonJsFileName} 必须导出 function`) + console.error(`${pagesJsonJsFileName} ${uniI18n.__('cliShared.requireExportFunction')}`) } } // 将 subpackages 转换成 subPackages @@ -112,7 +113,7 @@ function isNVuePage (page, root = '') { function isValidPage (page, root = '') { if (typeof page === 'string' || !page.path) { // 不合法的配置 - console.warn('pages.json 页面配置错误, 已被忽略, 查看文档: https://uniapp.dcloud.io/collocation/pages?id=pages') + console.warn(uniI18n.__('cliShared.pagesJsonError', { "0": 'https://uniapp.dcloud.io/collocation/pages?id=pages' })) return false } let pagePath = page.path @@ -390,9 +391,7 @@ function initAutoComponents () { }) if (conflictFiles.length > 0) { conflictFiles.forEach(files => { - console.warn('easycom组件冲突:[' + files.map((file, index) => { - return file - }).join(',') + ']') + console.warn(uniI18n.__('cliShared.easycomConflict', { "0": '[' + files.map((file, index) => { return file }).join(',') + ']' })) console.log('\n') }) } diff --git a/packages/uni-cli-shared/lib/plugin.js b/packages/uni-cli-shared/lib/plugin.js index 8ceac598d..beb79bb91 100644 --- a/packages/uni-cli-shared/lib/plugin.js +++ b/packages/uni-cli-shared/lib/plugin.js @@ -1,6 +1,6 @@ const path = require('path') - const initPreprocessContext = require('./preprocess') +const uniI18n = require('@dcloudio/uni-cli-i18n') const Plugin = { options: {}, @@ -25,7 +25,7 @@ function initPlugin (plugin) { try { pluginApi = require(path.join(plugin.id, (plugin.config.main || '/lib/uni.config.js'))) } catch (e) { - console.warn(`${plugin.id} 缺少 uni.config.js `) + console.warn(uniI18n.__('cliShared.missingUniConfig', { "0": plugin.id })) } pluginApi && PLUGIN_KEYS.forEach(name => { @@ -56,7 +56,7 @@ function resolvePlugins () { return } if (!config.name) { - return console.warn(`${id}/package.json->uni-app 缺少 name 属性`) + return console.warn(uniI18n.__('cliShared.missingNameAttribute', { "0": `${id}/package.json->uni-app` })) } return { id, @@ -71,13 +71,13 @@ function initExtends (name, plugin, plugins) { const extendsPlatform = plugin.config.extends if (extendsPlatform) { if (extendsPlatform !== 'h5') { - console.error('目前仅支持基于 h5 平台做扩展') + console.error(uniI18n.__('cliShared.extendOnlySupportH5')) process.exit(0) } if (!plugin) { - console.error(`缺少平台 ${extendsPlatform} 插件`) + console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { "0": extendsPlatform })) process.exit(0) - } + } const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform) process.env.UNI_SUB_PLATFORM = name process.env.UNI_PLATFORM = extendsPlatform @@ -102,7 +102,7 @@ module.exports = { const plugins = resolvePlugins() const plugin = plugins.find(plugin => plugin.name === process.env.UNI_PLATFORM) if (!plugin) { - console.error(`缺少平台 ${process.env.UNI_PLATFORM} 插件`) + console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { "0": process.env.UNI_PLATFORM })) process.exit(0) } const name = plugin.name @@ -119,4 +119,4 @@ module.exports = { return Plugin } -} +} diff --git a/packages/uni-migration/lib/index.js b/packages/uni-migration/lib/index.js index efe17b1c9..965ec0442 100644 --- a/packages/uni-migration/lib/index.js +++ b/packages/uni-migration/lib/index.js @@ -1,6 +1,6 @@ const path = require('path') const fs = require('fs-extra') - +const uniI18n = require('@dcloudio/uni-cli-i18n') const validate = require('./validate') const patchVant = require('./vant') @@ -13,7 +13,7 @@ module.exports = function migrate (input, out, options = {}) { options.platform = options.platform || 'mp-weixin' const migrater = migraters[options.platform] if (!migrater) { - return console.error(`错误: 目前支持 ${Object.keys(migraters).join(',')} 转换`) + return console.error(uniI18n.__('migration.errorOnlySupportConvert', { "0": Object.keys(migraters).join(',') })) } input = path.resolve(input) out = path.resolve(out || input) diff --git a/packages/uni-migration/lib/validate.js b/packages/uni-migration/lib/validate.js index b3c74ba31..acfbb999b 100644 --- a/packages/uni-migration/lib/validate.js +++ b/packages/uni-migration/lib/validate.js @@ -1,13 +1,13 @@ const fs = require('fs') const path = require('path') - +const uniI18n = require('@dcloudio/uni-cli-i18n') const migraters = { 'mp-weixin': require('./mp-weixin') } module.exports = function validate (input, out, options) { if (!fs.existsSync(input)) { - return console.error(`错误: '${input}' 不存在`) + return console.error(uniI18n.__('migration.errorInputNotExists', { "0": input })) } Object.assign(options, migraters[options.platform].options) const templateExtname = options.extname.template @@ -15,7 +15,7 @@ module.exports = function validate (input, out, options) { const stat = fs.lstatSync(input) if (stat.isFile()) { if (path.extname(input) !== templateExtname) { - return console.error(`错误: 单文件转换需要传入 ${templateExtname.substr(1)} 文件地址`) + return console.error(uniI18n.__('migration.errorConvertRequireFileUrl', { "0": templateExtname.substr(1) })) } options.target = 'file' } else if (stat.isDirectory()) { @@ -26,7 +26,7 @@ module.exports = function validate (input, out, options) { options.target = 'folder' } } else { - return console.error(`错误: '${input}' 不支持转换`) + return console.error(uniI18n.__('migration.errorCannotConvert', { "0": input })) } return true -} +} diff --git a/packages/uni-mp-weixin/lib/uni.compiler.js b/packages/uni-mp-weixin/lib/uni.compiler.js index 7fadec3b1..e5a8f5653 100644 --- a/packages/uni-mp-weixin/lib/uni.compiler.js +++ b/packages/uni-mp-weixin/lib/uni.compiler.js @@ -1,6 +1,6 @@ const path = require('path') - const t = require('@babel/types') +const uniI18n = require('@dcloudio/uni-cli-i18n') function generateJsCode (properties = '{}') { return ` @@ -107,7 +107,7 @@ module.exports = { ] if (t.isIdentifier(value)) { if (value.name !== key.name) { - state.errors.add(`解构插槽 Prop 时,不支持将${key.name}重命名为${value.name},重命名后会影响性能`) + state.errors.add(uniI18n.__('mpWeChat.slotPropNoSupportReanme', { "0": key.name, "1": value.name })) } } else if (t.isAssignmentPattern(value)) { valueObjectProperties.push(t.objectProperty(t.identifier('default'), value.right)) @@ -115,7 +115,7 @@ module.exports = { objectProperties.push(t.objectProperty(key, t.objectExpression(valueObjectProperties))) }) } else { - state.errors.add(`目前仅支持解构插槽 ${paramExprNode.name},如 v-slot="{ user }"`) + state.errors.add(uniI18n.__('mpWeChat.onlySupportDestructuringSlot', { "0": paramExprNode.name, "1": 'v-slot="{ user }"'})) } const jsContent = generateJsCode(genCode(t.objectExpression(objectProperties), true)) state.files[jsFile] = jsContent @@ -140,4 +140,4 @@ module.exports = { return '' } -} +} diff --git a/packages/uni-stat/src/parameter.js b/packages/uni-stat/src/parameter.js index bf8890c1d..dc765b1dd 100644 --- a/packages/uni-stat/src/parameter.js +++ b/packages/uni-stat/src/parameter.js @@ -5,6 +5,7 @@ import { STAT_VERSION, DIFF_TIME } from './config'; +const uniI18n = require('@dcloudio/uni-cli-i18n') const statConfig = require('uni-stat-config').default || require('uni-stat-config'); const UUID_KEY = '__DC_STAT_UUID'; const UUID_VALUE = '__DC_UUID_VALUE'; @@ -276,30 +277,30 @@ export const getPageTypes = (self) => { export const calibration = (eventName, options) => { // login 、 share 、pay_success 、pay_fail 、register 、title if (!eventName) { - console.error(`uni.report 缺少 [eventName] 参数`); + console.error(`uni.report ${uniI18n.__('uniStat.missingParameter')}`); return true } if (typeof eventName !== 'string') { - console.error(`uni.report [eventName] 参数类型错误,只能为 String 类型`); + console.error(`uni.report [eventName] ${uniI18n.__('uniStat.parameterTypeErrrorString')}`); return true } if (eventName.length > 255) { - console.error(`uni.report [eventName] 参数长度不能大于 255`); + console.error(`uni.report [eventName] ${uniI18n.__('uniStat.parameterLengthLess')} 255`); return true } if (typeof options !== 'string' && typeof options !== 'object') { - console.error(`uni.report [options] 参数类型错误,只能为 String 或 Object 类型`); + console.error('uni.report [options] ' + uniI18n.__('uniStat.parameterTypeErrrorStringOrObject')); return true } if (typeof options === 'string' && options.length > 255) { - console.error(`uni.report [options] 参数长度不能大于 255`); + console.error(`uni.report [options] ${uniI18n.__('uniStat.parameterLengthLess')} 255`); return true } if (eventName === 'title' && typeof options !== 'string') { - console.error('uni.report [eventName] 参数为 title 时,[options] 参数只能为 String 类型'); + console.error(`uni.report [eventName] ${uniI18n.__('uniStat.hasTitleOptionString')}`); return true } } @@ -390,4 +391,4 @@ const requestData = (done) => { }) } }); -} +} diff --git a/packages/uni-template-compiler/lib/mp.js b/packages/uni-template-compiler/lib/mp.js index 204dc8be0..ef16ef5b5 100644 --- a/packages/uni-template-compiler/lib/mp.js +++ b/packages/uni-template-compiler/lib/mp.js @@ -1,3 +1,5 @@ +const uniI18n = require('@dcloudio/uni-cli-i18n') + const EVENTS = { click: 'tap' } @@ -100,7 +102,7 @@ ${content} return `${eventType}${eventName}` // 原生组件不支持 bind:input 等写法,统一使用 bindinput }, createScopedSlots (slotName, props, state) { - state.errors.add('暂不支持 scoped slot [' + slotName + ']') + state.errors.add(uniI18n.__('templateCompiler.notCurrentlySupportScopedSlot', { "0": `[${slotName}]` })) return { type: 'slot', attr: { @@ -113,7 +115,7 @@ ${content} traverseExpr, normalizeChildren }, state) { - state.errors.add('暂不支持 scoped slot [' + slotName + ']') + state.errors.add(uniI18n.__('templateCompiler.notCurrentlySupportScopedSlot', { "0": `[${slotName}]` })) return { type: 'view', attr: { diff --git a/packages/uni-template-compiler/lib/script/traverse/data/class.js b/packages/uni-template-compiler/lib/script/traverse/data/class.js index 39ff44ca6..ac7a0cc3e 100644 --- a/packages/uni-template-compiler/lib/script/traverse/data/class.js +++ b/packages/uni-template-compiler/lib/script/traverse/data/class.js @@ -1,4 +1,5 @@ const t = require('@babel/types') +const uniI18n = require('@dcloudio/uni-cli-i18n') const { getCode @@ -132,7 +133,7 @@ module.exports = function processClass (paths, path, state) { // ) // ) } else { - state.errors.add(`:class 不支持 ${getCode(classValuePath.node)} 语法`) + state.errors.add(':class' + uniI18n.__('templateCompiler.noSupportSyntax', { "0": getCode(classValuePath.node) })) } } return [] diff --git a/packages/uni-template-compiler/lib/script/traverse/visitor.js b/packages/uni-template-compiler/lib/script/traverse/visitor.js index e653a594f..089d69aa3 100644 --- a/packages/uni-template-compiler/lib/script/traverse/visitor.js +++ b/packages/uni-template-compiler/lib/script/traverse/visitor.js @@ -1,4 +1,5 @@ const t = require('@babel/types') +const uniI18n = require('@dcloudio/uni-cli-i18n') const { METHOD_CREATE_ELEMENT, @@ -77,7 +78,7 @@ function addVueId (path, state) { const scoped = scopeds[i] forIndexSet.add(scoped.forIndex) if (forIndexSet.size !== i + 1) { - state.errors.add(`v-for 嵌套时,索引名称 ${scoped.forIndex} 不允许重复`) + state.errors.add(uniI18n.__('templateCompiler.forNestedIndexNameNoArrowRepeat', { "0": 'v-for', "1": scoped.forIndex })) break } } diff --git a/packages/uni-template-compiler/lib/template/generate.js b/packages/uni-template-compiler/lib/template/generate.js index 6c0b34db0..ab98c29ce 100644 --- a/packages/uni-template-compiler/lib/template/generate.js +++ b/packages/uni-template-compiler/lib/template/generate.js @@ -6,6 +6,7 @@ const { SELF_CLOSING_TAGS, INTERNAL_EVENT_LINK } = require('../constants') +const uniI18n = require('@dcloudio/uni-cli-i18n') function processElement (ast, state, isRoot) { const platformName = state.options.platform.name @@ -81,7 +82,7 @@ function processElement (ast, state, isRoot) { ast.attr['vue-slots'] = '{{[' + slots.reverse().map(slotName => `'${slotName}'`).join(',') + ']}}' } if (ast.attr.id && ast.attr.id.indexOf('{{') === 0) { - state.tips.add(`id 作为属性保留名,不允许在自定义组件 ${ast.type} 中定义为 props`) + state.tips.add(uniI18n.__('templateCompiler.idAttribNotAllowInCustomComponentProps', { "0": ast.type })) } if (hasOwn(ast.attr, 'data') && platformName !== 'mp-toutiao') { // 百度中会出现异常情况 // TODO 暂不输出 diff --git a/packages/uni-template-compiler/lib/template/traverse.js b/packages/uni-template-compiler/lib/template/traverse.js index e2af15127..6639c22a8 100644 --- a/packages/uni-template-compiler/lib/template/traverse.js +++ b/packages/uni-template-compiler/lib/template/traverse.js @@ -4,6 +4,7 @@ const t = require('@babel/types') const babelTraverse = require('@babel/traverse').default const generate = require('./generate') +const uniI18n = require('@dcloudio/uni-cli-i18n') const { genCode, @@ -297,7 +298,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) { function traverseRenderSlot (callExprNode, state) { if (!t.isStringLiteral(callExprNode.arguments[0])) { - state.errors.add('v-slot 不支持动态插槽名') + state.errors.add(uniI18n.__('templateCompiler.notSupportDynamicSlotName', { "0": 'v-slot' })) return } diff --git a/packages/uni-template-compiler/lib/util.js b/packages/uni-template-compiler/lib/util.js index f482a3e8c..cd3d76957 100644 --- a/packages/uni-template-compiler/lib/util.js +++ b/packages/uni-template-compiler/lib/util.js @@ -1,6 +1,7 @@ const t = require('@babel/types') const babelTraverse = require('@babel/traverse').default const babelGenerate = require('@babel/generator').default +const uniI18n = require('@dcloudio/uni-cli-i18n') const { METHOD_RENDER_LIST @@ -115,7 +116,7 @@ function getForKey (forKey, forIndex, state) { } else if (t.isMemberExpression(forKey)) { return forKey.property.name || forKey.property.value } else { - state.tips.add(`非 h5 平台 :key 不支持表达式 ${getCode(forKey)},详情参考:https://uniapp.dcloud.io/use?id=key`) + state.tips.add(uniI18n.__('templateCompiler.noH5KeyNoSupportExpression', { "0": getCode(forKey), "1": 'https://uniapp.dcloud.io/use?id=key' })) } } return '' diff --git a/packages/vue-cli-plugin-hbuilderx/index.js b/packages/vue-cli-plugin-hbuilderx/index.js index e510b8e1e..def14c9ee 100644 --- a/packages/vue-cli-plugin-hbuilderx/index.js +++ b/packages/vue-cli-plugin-hbuilderx/index.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const uniI18n = require('@dcloudio/uni-cli-i18n') process.env.UNI_CLI_CONTEXT = path.resolve(__dirname, '../../../') @@ -18,7 +19,7 @@ module.exports = (api, options) => { // 仅处理 app-plus 相关逻辑 !process.env.UNI_USING_V3_NATIVE ) { if (!fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'weapp-tools/lib/index.js'))) { - console.error('请使用 HBuilderX 编译运行至 app-plus 平台') + console.error(uniI18n.__('pluginHbuilderx.plaseHXCompileAppPlatform')) process.exit(0) } } @@ -36,4 +37,4 @@ module.exports = (api, options) => { // 仅处理 app-plus 相关逻辑 plugins } }) -} +} diff --git a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js index 64c07a643..b99f48b93 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const uniI18n = require('@dcloudio/uni-cli-i18n') const { log, @@ -19,7 +20,7 @@ let isFirst = true let compiling = false class WebpackAppPlusPlugin { apply (compiler) { - if (process.env.UNI_USING_V3) { + if (process.env.UNI_USING_V3) { const chunkVersions = {} const entry = compiler.options.entry() @@ -31,7 +32,7 @@ class WebpackAppPlusPlugin { compiler.hooks.invalid.tap('WebpackAppPlusPlugin', (fileName, changeTime) => { if (!compiling) { compiling = true - console.log('开始差量编译...') + console.log(uniI18n.__('performingHotReload')) } }) @@ -100,7 +101,7 @@ class WebpackAppPlusPlugin { }) } else { compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { return resolve() } @@ -137,4 +138,4 @@ class WebpackAppPlusPlugin { } } -module.exports = WebpackAppPlusPlugin +module.exports = WebpackAppPlusPlugin diff --git a/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style.js b/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style.js index 499a14f82..256d53879 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style.js @@ -7,6 +7,7 @@ module.exports = function (content, map) { this.cacheable && this.cacheable() this.callback(null, 'module.exports = ' + genStyleString(content, this), map) } +const uniI18n = require('@dcloudio/uni-cli-i18n') // @todo: // font-relative lengths: em, ex, ch, ic @@ -52,9 +53,7 @@ function genStyleString (input, loader) { }) if (msgs.length) { if (isFirst) { - msgs.unshift( - 'nvue中不支持如下css。如全局或公共样式受影响,建议将告警样式写在ifndef APP-PLUS-NVUE的条件编译中,详情如下:' - ) + msgs.unshift(uniI18n.__('pluginHbuilderx.nvueCssWarning')) isFirst = false } msgs.forEach(msg => console.warn(msg)) diff --git a/packages/vue-cli-plugin-hbuilderx/template/bin/uniapp-cli.js b/packages/vue-cli-plugin-hbuilderx/template/bin/uniapp-cli.js index 65608070f..742c5cfc3 100644 --- a/packages/vue-cli-plugin-hbuilderx/template/bin/uniapp-cli.js +++ b/packages/vue-cli-plugin-hbuilderx/template/bin/uniapp-cli.js @@ -1,9 +1,10 @@ #!/usr/bin/env node +const uniI18n = require('@dcloudio/uni-cli-i18n') // TODO 暂时处理安装目录包含特殊符号,导致 H5 预览资源加载失败的问题。 const matchSymbol = __dirname.match(/[()]/) if (matchSymbol) { - console.error(`编译失败:HBuilderX 安装目录不能包括 ${matchSymbol[0]} 等特殊字符`) + console.error(uniI18n.__('pluginHbuilderx.hxBuildFailed', { "0": matchSymbol[0] })) process.exit(0) } @@ -22,10 +23,10 @@ process.env.UNI_OUTPUT_DIR = path.resolve(process.env.UNI_OUTPUT_DIR) const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd()) service.run((process.env.NODE_ENV === 'development' && process.env.UNI_PLATFORM === 'h5') ? 'uni-serve' : 'uni-build', { - watch: process.env.NODE_ENV === 'development', + watch: process.env.NODE_ENV === 'development', minimize: process.env.UNI_MINIMIZE === 'true', clean: false }).catch(err => { error(err) process.exit(1) -}) +}) diff --git a/packages/vue-cli-plugin-uni/commands/build.js b/packages/vue-cli-plugin-uni/commands/build.js index ceb204a51..cf8901744 100644 --- a/packages/vue-cli-plugin-uni/commands/build.js +++ b/packages/vue-cli-plugin-uni/commands/build.js @@ -5,6 +5,8 @@ const { isInHBuilderX } = require('@dcloudio/uni-cli-shared') +const uniI18n = require('@dcloudio/uni-cli-i18n') + const defaults = { clean: true, target: 'app', @@ -48,7 +50,7 @@ module.exports = (api, options) => { process.env.UNI_MP_PLUGIN = args.plugin analysisPluginDir() } else { - console.error('编译到小程序插件只支持微信小程序') + console.error(uniI18n.__('pluginUni.compileToMpPluginOnlySupportWeChat')) process.exit(0) } } @@ -129,7 +131,7 @@ async function build (args, api, options) { log() if (!runByHBuilderX && !runByAliIde) { - logWithSpinner(`开始编译当前项目至 ${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM} 平台...`) + logWithSpinner(uniI18n.__('pluginUni.startCompileProjectToPlatform', { "0": (process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM) })) } const targetDir = api.resolve(options.outputDir) @@ -214,7 +216,7 @@ function analysisPluginDir () { const pluginJsonPath = path.resolve(process.env.UNI_INPUT_DIR, pluginJsonName) if (!fs.pathExistsSync(pluginJsonPath)) { - console.error(`${pluginJsonName}文件不存在,请检查后重试`) + console.error(uniI18n.__('pluginUni.fileNoExistsCheckAfterRetry', { "0": pluginJsonName })) process.exit(0) } @@ -226,7 +228,7 @@ function analysisPluginDir () { const mainFilePath = path.resolve(process.env.UNI_INPUT_DIR, UNI_MP_PLUGIN_MAIN) if (UNI_MP_PLUGIN_MAIN && !fs.pathExistsSync(mainFilePath)) { - console.error(`${UNI_MP_PLUGIN_MAIN}入口文件不存在,请检查后重试`) + console.error(uniI18n.__('pluginUni.entryDileNoExistsCheckAfterRetry', { "0": UNI_MP_PLUGIN_MAIN })) process.exit(0) } diff --git a/packages/vue-cli-plugin-uni/lib/commands/custom.js b/packages/vue-cli-plugin-uni/lib/commands/custom.js index e18ca2640..f028c59ea 100644 --- a/packages/vue-cli-plugin-uni/lib/commands/custom.js +++ b/packages/vue-cli-plugin-uni/lib/commands/custom.js @@ -5,11 +5,12 @@ const Service = require('@vue/cli-service') const { initCustomScript } = require('@dcloudio/uni-cli-shared/lib/package') +const uniI18n = require('@dcloudio/uni-cli-i18n') module.exports = function custom (argv) { const script = argv._[1] if (!script) { - console.error('请指定 package.json->uni-app->scripts 下的 script 名称') + console.error(uniI18n.__('pluginUni.pleaseConfigScriptName')) process.exit(0) } @@ -37,4 +38,4 @@ module.exports = function custom (argv) { console.error(err) process.exit(1) }) -} +} diff --git a/packages/vue-cli-plugin-uni/lib/commands/invoke.js b/packages/vue-cli-plugin-uni/lib/commands/invoke.js index 9d58d42fe..9c1d21b90 100644 --- a/packages/vue-cli-plugin-uni/lib/commands/invoke.js +++ b/packages/vue-cli-plugin-uni/lib/commands/invoke.js @@ -1,21 +1,22 @@ const fs = require('fs') const path = require('path') +const uniI18n = require('@dcloudio/uni-cli-i18n') module.exports = async function add (argv) { const pluginName = argv._[1] if (!pluginName) { - console.error('请指定插件名称') + console.error(uniI18n.__('pluginUni.pleaseSpecifyPluginName')) process.exit(0) } const pluginPkg = require(pluginName + '/package.json') const options = pluginPkg['uni-app'] if (!options) { - console.error('插件不合法') + console.error(uniI18n.__('pluginUni.pluginIllegal')) process.exit(0) } const name = options.name if (!name) { - console.error('插件名称不存在') + console.error(uniI18n.__('pluginUni.pluginNameNotExist')) process.exit(0) } const scripts = options.scripts || { @@ -38,4 +39,4 @@ module.exports = async function add (argv) { if (changed) { fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)) } -} +} diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index f27a62d71..8538192ae 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -2,6 +2,7 @@ const fs = require('fs') const path = require('path') const mkdirp = require('mkdirp') const loaderUtils = require('loader-utils') +const uniI18n = require('@dcloudio/uni-cli-i18n') require('./error-reporting') @@ -44,7 +45,7 @@ if (process.env.UNI_CLOUD_SPACES) { const hasUniCloudSpace = spaces.length > 0 if (spaces.length === 1) { const space = spaces[0] - console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`) + console.log(uniI18n.__('pluginUni.currentProjectDefaultSpaceId', { "0": space.id })) } if ( @@ -52,16 +53,13 @@ if (process.env.UNI_CLOUD_SPACES) { isH5 && isProduction ) { - console.warn( - '发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5') + console.warn(uniI18n.__('pluginUni.unicloudReleaseH5', { "0": 'https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5' })) } else if ( hasUniCloudSpace && isH5 && !isProduction ) { - console.warn( - '当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5' - ) + console.warn(uniI18n.__('pluginUni.unicloudShowedRunByHBuilderX', { "0": 'https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5' })) } process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => { @@ -283,7 +281,7 @@ if ( process.env.UNI_USING_STAT = true if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') { console.log() - console.warn('当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303') + console.warn(uniI18n.__('pluginUni.uniStatisticsNoAppid', { "0": 'https://ask.dcloud.net.cn/article/36303' })) console.log() } } @@ -309,18 +307,18 @@ const warningMsg = const needWarning = !platformOptions.usingComponents || usingComponentsAbsent let hasNVue = false // 输出编译器版本等信息 +const compile_mode_url = 'https://ask.dcloud.net.cn/article/36074' if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { - console.log('当前nvue编译模式' + (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + ':' + (isNVueCompiler ? 'uni-app' - : 'weex') + - ' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074') + let compile_mode = (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + ':' + (isNVueCompiler ? 'uni-app' : 'weex') + console.log(uniI18n.__('pluginUni.nvueCompileModeForDetail', { "0": compile_mode, "1": compile_mode_url })) } else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp-native') { try { let info = '' if (process.env.UNI_PLATFORM === 'app-plus') { const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json') if (pagesPkg) { - const v3Tips = '(v3)详见:https://ask.dcloud.net.cn/article/36599。' - info = '编译器版本:' + pagesPkg['uni-app'].compilerVersion + (process.env.UNI_USING_V3 ? v3Tips : '') + const v3Tips = `(v3)${uniI18n.__('see')}:https://ask.dcloud.net.cn/article/36599。` + info = uniI18n.__('compilerVersion') + ':' + pagesPkg['uni-app'].compilerVersion + (process.env.UNI_USING_V3 ? v3Tips : '') } if (process.env.UNI_USING_V3) { console.log(info) @@ -334,8 +332,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { if (needWarning) { console.log(warningMsg) } - console.log('当前nvue编译模式:' + (isNVueCompiler ? 'uni-app' : 'weex') + - ' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074') + console.log(uniI18n.__('pluginUni.nvueCompileModeForDetail', { "0": (isNVueCompiler ? 'uni-app' : 'weex'), "1": compile_mode_url })) } else { console.log(info) if (needWarning) { @@ -351,11 +348,11 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { } catch (e) {} } if (process.env.NODE_ENV !== 'production') { // 运行模式性能提示 - let perfMsg = '请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。' + let perfMsg = uniI18n.__('pluginUni.runDebugMode') if (hasNVue) { // app-nvue - perfMsg = perfMsg + '尤其是app-nvue的sourcemap影响较大' + perfMsg = perfMsg + uniI18n.__('pluginUni.runDebugModeNvue') } else if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) { // 小程序 - perfMsg = perfMsg + '若要正式发布,请点击发行菜单或使用cli发布命令进行发布' + perfMsg = perfMsg + uniI18n.__('pluginUni.runDebugModeMP') } console.log(perfMsg) } @@ -394,7 +391,7 @@ if (runByHBuilderX) { '[BABEL] Note: The code generator has deoptimised the styling of')) { const filePath = msg.replace('[BABEL] Note: The code generator has deoptimised the styling of ', '').split( ' as ')[0] - console.log('[警告] `' + path.relative(process.env.UNI_INPUT_DIR, filePath) + + console.log('[' + uniI18n.__('warning') + '] `' + path.relative(process.env.UNI_INPUT_DIR, filePath) + '` 文件体积超过 500KB,已跳过压缩以及 ES6 转 ES5 的处理,手机端使用过大的js库影响性能。') } else { oldError.apply(console, arguments) @@ -458,10 +455,10 @@ if ( } if (process.env.UNI_PLATFORM.startsWith('mp-')) { - console.log('小程序各家浏览器内核及自定义组件实现机制存在差异,可能存在样式布局兼容问题,参考:https://uniapp.dcloud.io/matter?id=mp') + console.log(uniI18n.__('pluginUni.mpBrowserKernelDifference', { "0": "https://uniapp.dcloud.io/matter?id=mp" })) } -runByHBuilderX && console.log('正在编译中...') +runByHBuilderX && console.log(uniI18n.__('compiling')) module.exports = { manifestPlatformOptions: platformOptions diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/plugin/index.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/plugin/index.js index 3d86ce90b..f60e5555d 100644 --- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/plugin/index.js +++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/plugin/index.js @@ -4,6 +4,7 @@ const { const { initUniModules } = require('@dcloudio/uni-cli-shared/lib/uni_modules') +const uniI18n = require('@dcloudio/uni-cli-i18n') let compiling = false @@ -34,7 +35,7 @@ class WebpackUniAppPlugin { if (!process.env.UNI_USING_V3) { if (!compiling) { compiling = true - console.log('开始差量编译...') + console.log(uniI18n.__('performingHotReload')) } } if (fileName && typeof fileName === 'string') { @@ -59,4 +60,4 @@ class WebpackUniAppPlugin { } } -module.exports = WebpackUniAppPlugin +module.exports = WebpackUniAppPlugin diff --git a/packages/webpack-uni-mp-loader/lib/babel-plugin-global-component.js b/packages/webpack-uni-mp-loader/lib/babel-plugin-global-component.js index 94c3e316a..beef36992 100644 --- a/packages/webpack-uni-mp-loader/lib/babel-plugin-global-component.js +++ b/packages/webpack-uni-mp-loader/lib/babel-plugin-global-component.js @@ -1,3 +1,5 @@ +const uniI18n = require('@dcloudio/uni-cli-i18n') + function addImportsMap (metadata, name, source) { if (!metadata.modules) { metadata.modules = {} @@ -29,10 +31,10 @@ module.exports = function babelPluginGlobalComponent ({ } if (callee.object.name === 'Vue' && callee.property.name === 'component') { if (!args[0] || args[0].type !== 'StringLiteral') { - throw new Error('Vue.component()的第一个参数必须为静态字符串') + throw new Error(uniI18n.__('mpLoader.firstParameterNeedStaticString', { "0": "Vue.component()" })) } if (!args[1]) { - throw new Error('Vue.component()需要两个参数') + throw new Error(uniI18n.__('mpLoader.requireTwoParameter', { "0": "Vue.component()" })) } if (!metadata.globalComponents) { metadata.globalComponents = {} @@ -64,4 +66,4 @@ module.exports = function babelPluginGlobalComponent ({ } } } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/babel-plugin-scoped-component.js b/packages/webpack-uni-mp-loader/lib/babel-plugin-scoped-component.js index d4279db61..8714f3dae 100644 --- a/packages/webpack-uni-mp-loader/lib/babel-plugin-scoped-component.js +++ b/packages/webpack-uni-mp-loader/lib/babel-plugin-scoped-component.js @@ -1,3 +1,5 @@ +const uniI18n = require('@dcloudio/uni-cli-i18n') + const hyphenateRE = /\B([A-Z])/g function cached (fn) { @@ -63,7 +65,7 @@ module.exports = function ({ const value = prop.value.name const source = findSource(value, path.scope.bindings) if (!source) { - throw new Error(`组件 ${key} 引用错误`) + throw new Error(uniI18n.__('mpLoader.componentReferenceError', { "0": key })) } if (process.UNI_LIBRARIES.includes(source)) { const componentName = hyphenate(key) @@ -86,4 +88,4 @@ module.exports = function ({ return binding.path.parent.source.value } } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js b/packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js index 58b88cfd0..7825671ae 100644 --- a/packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js +++ b/packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js @@ -5,6 +5,8 @@ const { parseComponents } = require('./util') +const uniI18n = require('@dcloudio/uni-cli-i18n') + module.exports = function (ast, state = {}) { const imports = [] let bindings = false @@ -22,10 +24,10 @@ module.exports = function (ast, state = {}) { const nameNode = args[0] const valueNode = args[1] if (!t.isStringLiteral(nameNode)) { - throw new Error('Vue.component()的第一个参数必须为静态字符串') + throw new Error(uniI18n.__('mpLoader.firstParameterNeedStaticString', { "0": "Vue.component()" })) } if (!t.isIdentifier(valueNode)) { - throw new Error('Vue.component()需要两个参数') + throw new Error(uniI18n.__('mpLoader.requireTwoParameter', { "0": "Vue.component()" })) } imports.push({ name: nameNode.value, @@ -43,4 +45,4 @@ module.exports = function (ast, state = {}) { ast, state } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/babel/util.js b/packages/webpack-uni-mp-loader/lib/babel/util.js index e9e172414..eef366b94 100644 --- a/packages/webpack-uni-mp-loader/lib/babel/util.js +++ b/packages/webpack-uni-mp-loader/lib/babel/util.js @@ -1,4 +1,5 @@ const t = require('@babel/types') +const uniI18n = require('@dcloudio/uni-cli-i18n') const hyphenateRE = /\B([A-Z])/g @@ -34,7 +35,7 @@ function parseComponents (names, bindings, path) { }) => { const importDeclaration = findImportDeclaration(value, bindings) if (!importDeclaration) { - throw new Error(`组件 ${name} 引用错误,仅支持 import 方式引入组件`) + throw new Error(uniI18n.__('mpLoader.componentReferenceErrorOnlySupportImport', { "0": name })) } let source = importDeclaration.node.source.value if (process.UNI_LIBRARIES && process.UNI_LIBRARIES.includes(source)) { @@ -63,8 +64,8 @@ function parseComponents (names, bindings, path) { function findBabelLoader (loaders) { return loaders.find(loader => loader.path.indexOf('babel-loader') !== -1) -} - +} + const babelPluginDynamicImport = require.resolve('./plugin-dynamic-import') function addDynamicImport (babelLoader, resourcePath, dynamicImports) { @@ -82,4 +83,4 @@ module.exports = { addDynamicImport, findBabelLoader, parseComponents -} +} diff --git a/packages/webpack-uni-mp-loader/lib/main-new.js b/packages/webpack-uni-mp-loader/lib/main-new.js index a6b9851a9..930ba8aaf 100644 --- a/packages/webpack-uni-mp-loader/lib/main-new.js +++ b/packages/webpack-uni-mp-loader/lib/main-new.js @@ -37,6 +37,8 @@ const traverse = require('./babel/global-component-traverse') const babelPluginCreateApp = require.resolve('./babel/plugin-create-app') +const uniI18n = require('@dcloudio/uni-cli-i18n') + function addCreateApp (babelLoader) { babelLoader.options = babelLoader.options || {} if (!babelLoader.options.plugins) { @@ -89,7 +91,7 @@ createPage(Page) const babelLoader = findBabelLoader(this.loaders) if (!babelLoader) { - throw new Error('babel-loader 查找失败') + throw new Error(uniI18n.__('mpLoader.findFail', { "0": "babel-loader" })) } else { addCreateApp(babelLoader) } @@ -136,4 +138,4 @@ createPage(Page) callback(err, content, map) }) } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/script-new.js b/packages/webpack-uni-mp-loader/lib/script-new.js index 335552e44..4783ba1ac 100644 --- a/packages/webpack-uni-mp-loader/lib/script-new.js +++ b/packages/webpack-uni-mp-loader/lib/script-new.js @@ -12,7 +12,7 @@ const { const { getBabelParserOptions -} = require('@dcloudio/uni-cli-shared/lib/platform') +} = require('@dcloudio/uni-cli-shared/lib/platform') const { isBuiltInComponentPath @@ -36,6 +36,8 @@ const { addDynamicImport } = require('./babel/util') +const uniI18n = require('@dcloudio/uni-cli-i18n') + module.exports = function (content, map) { this.cacheable && this.cacheable() @@ -65,7 +67,7 @@ module.exports = function (content, map) { if ( // windows 上 page-meta, navigation-bar 可能在不同盘上 /^win/.test(process.platform) && - path.isAbsolute(resourcePath) && + path.isAbsolute(resourcePath) && isBuiltInComponentPath(resourcePath) ) { resourcePath = normalizePath(path.relative(process.env.UNI_CLI_CONTEXT, resourcePath)) @@ -124,7 +126,7 @@ module.exports = function (content, map) { const babelLoader = findBabelLoader(this.loaders) if (!babelLoader) { - callback(new Error('babel-loader 查找失败'), content) + callback(new Error(uniI18n.__('mpLoader.findFail', { "0": "babel-loader" })), content) } else { addDynamicImport(babelLoader, resourcePath, dynamicImports) @@ -134,4 +136,4 @@ module.exports = function (content, map) { }, err => { callback(err, content, map) }) -} +} diff --git a/packages/webpack-uni-pages-loader/lib/index-new.js b/packages/webpack-uni-pages-loader/lib/index-new.js index 648da5d45..554ab79fb 100644 --- a/packages/webpack-uni-pages-loader/lib/index-new.js +++ b/packages/webpack-uni-pages-loader/lib/index-new.js @@ -26,6 +26,8 @@ const { initAutoImportComponents } = require('@dcloudio/uni-cli-shared/lib/pages') +const uniI18n = require('@dcloudio/uni-cli-i18n') + const parseStyle = require('./util').parseStyle // 将开发者手动设置的 usingComponents 调整名称,方便与自动解析到的 usingComponents 做最后合并 @@ -63,7 +65,7 @@ module.exports = function (content, map) { }) if (!pagesJson.pages || pagesJson.pages.length === 0) { - console.error('pages.json中的pages不能为空') + console.error(uniI18n.__('pagesLoader.pagesNodeCannotNull')) process.exit(0) } @@ -110,7 +112,7 @@ module.exports = function (content, map) { if (!isAppView && jsonFile.name === 'manifest.json') { const content = JSON.parse(jsonFile.content) if (!content.launch_path && content.plus['uni-app'].nvueLaunchMode === 'fast') { - console.log('Nvue 首页启动模式: fast 详见: https://ask.dcloud.net.cn/article/36749') + console.log(uniI18n.__('pagesLoader.nvueFirstPageStartModeIsFast', { "0": "https://ask.dcloud.net.cn/article/36749" })) } } if (jsonFile.name === 'define-pages.js') { @@ -149,4 +151,4 @@ module.exports = function (content, map) { } this.callback(null, '', map) -} +} diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp.js b/packages/webpack-uni-pages-loader/lib/platforms/mp.js index 7b2a9fb16..92503f4ea 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/mp.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/mp.js @@ -23,6 +23,8 @@ const { trimMPJson } = require('../util') +const uniI18n = require('@dcloudio/uni-cli-i18n') + function defaultCopy (name, value, json) { json[name] = value } @@ -40,7 +42,7 @@ const pagesJson2AppJson = { tabBar: function (name, value, json, fromJson) { if (value && value.list && value.list.length) { if (value.list.length < 2) { - console.error('tabBar.list 需至少包含2项') + console.error(uniI18n.__('pagesLoader.pagesTabbarMinItem2', { "0": "tabBar.list" })) } const pages = json.pages value.list.forEach((page, index) => { @@ -55,9 +57,7 @@ const pagesJson2AppJson = { }) => path === (page.pagePath + '.html')) ) ) { - console.error( - `pages.json tabBar['list'][${index}]['pagePath'] "${page.pagePath}" 需在 pages 数组中` - ) + console.error(uniI18n.__('pagesLoader.needInPagesNode', { "0": `pages.json tabBar['list'][${index}]['pagePath'] "${page.pagePath}"` })) } } }) -- GitLab