diff --git a/packages/uni-cli-i18n/lib/index.js b/packages/uni-cli-i18n/lib/index.js index 496e99a0d39289a31ff4a54cfa60825f33c521cd..c96220a04d0a0856a718839d436de48992a1343b 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 9e26dfeeb6e641a33dae4961196235bdb965b21b..9c57bdb6ec97791bc9ee14d7c6c2729ff12682b5 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 9e26dfeeb6e641a33dae4961196235bdb965b21b..df9050fb44d3e3a8678d35fca45d9b50cc8d7f26 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 b2db2beeaef3d07442d9af1c4b8cdf2317941e8a..810173e88f4a1d0805b4bc0585f8fbc084d8c5cc 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 4a5fc5e3631b6f2266af2deed8310c4bb96691da..8526df6582e10166c85397ad8714b8d31d87b432 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 d19f2d3f98974f84cac95e57d252261c369d6e70..5eb3f5ff24ae09dab6ca5e10171079db2236bc23 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 8ceac598d2592875acc02018fc6e0cd99aa42aba..beb79bb911b14c52a05a83720d063a0d0f19a106 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 efe17b1c9932120b55b2f72412a113e1252a69c1..965ec04428f674098483e5cf23bb54c31ab8ded4 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 b3c74ba315e587e70dadbe201d7dd5cdb2c1dbd9..acfbb999b40318bdc60e0a01578b14b870cd2f7f 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 7fadec3b15097b906ee2c38421fc0772b3db7d0b..e5a8f5653afb9d9c576a18f1d4d4aa208f9d6187 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 bf8890c1d7fde31354d9ea6643993086977fba67..dc765b1dd8a6a63db3e966bbdb710b40a54eca4a 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 204dc8be00df15532bcf96344535075b0599c2d5..ef16ef5b51835b76759bf451cb297d78ab5c95f8 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 39ff44ca6ca304a063d9c2ba76148825de71398b..ac7a0cc3ea5336fe3438d47e7eade8d92aa87b38 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 e653a594fab4e7c9dbf3975e285cd380cd085e4e..089d69aa399e7832b62ba6f97d64a13b5ff7b81a 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 6c0b34db0351d3742448ae1c5ec7e485f0dd64ec..ab98c29ceccca250bd61344d491080e6b8260d2c 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 e2af15127e304a74261ea00fda1c0f07f7016e37..6639c22a898bb389448f73115706695f1a848f65 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 f482a3e8c17a8f8aa5e29e471f58647c20f470b1..cd3d769576d59cff430b7c91d87271aa0a7ca4c6 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 e510b8e1e581457bce9d545daea1c9248ee34f76..def14c9eee59d5598f091279d38a6e046d17ff94 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 64c07a6436ddb06e6f5110de40c5e61c37927a47..b99f48b934c87679d015baea5f11a9328dfb3840 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 499a14f826bf30ebab45b236e2225e85aa3a2f31..256d538799059212fa5b9d6ead41a28e7307d261 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 65608070fb749f10f3dd8e8ac7a11a90eeccd3be..742c5cfc3a7ecb21e8aa945af960d76457e6fcf0 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 ceb204a515f23a2ba856d47505bfac1d3100368e..cf8901744bd9517f05088525e399a34565cf68dd 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 e18ca26403b0e7131e5e8640cc1f653053d10a23..f028c59ea6ddfb3295478b5cf44600aaea79f15b 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 9d58d42fe6f31dd3eafcfc324364995eda82b097..9c1d21b90e899fdc2f085c16aa8f9b1832875592 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 f27a62d71b81562fb68a3f663d2a0e33332ca4dc..8538192ae15c92d9a35b730d864907064220ed73 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 3d86ce90ba68f8363c0f5dcbdce1f00f0f246bae..f60e5555d19343423427e9c44139489e84089179 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 94c3e316a8defa19f1afcc102970037347b2a770..beef3699221cc701a90b1696067b185c4759639a 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 d4279db61d604108277c8bbea809212509aea6bc..8714f3dae97998d786ff34487254b41f328e7d7d 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 58b88cfd069fb83e69f3a79a36874cf5055ce4e6..7825671aed4c3131ffdcd8eda496cf8179353142 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 e9e172414e29de175b8efad90e9a8e7d0d2d1bd4..eef366b940c82185dbede5d711535146eaf7d23c 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 a6b9851a9c8fbe40c57788731105c09282ee251c..930ba8aaf0c68c94e2a240e5962df51dfba47fc2 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 335552e4422a9cd6259a5ef607f3e5c005edc0be..4783ba1aca399d7e3787e8a641f450ae70e5887a 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 648da5d45366d23f642b50f2140490403e237666..554ab79fb67e8c82166a2358801b3e89f6aa275d 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 7b2a9fb16cc42ae1643f92386f5d3caed4384929..92503f4eaeed59b252a147b6aca1bb4d91ca84e4 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}"` })) } } })