webpack-gc-i18n-plugin 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/customLoader/index.cjs +69 -27
- package/dist/customLoader/index.cjs.map +1 -1
- package/dist/customLoader/index.mjs +69 -27
- package/dist/customLoader/index.mjs.map +1 -1
- package/dist/index.cjs +73 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.mjs +72 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -272,6 +272,8 @@ type BaseExtendsType = {
|
|
|
272
272
|
}>) => string;
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
+
declare const DEFAULT_ORIGIN_LANG = "zh-cn";
|
|
276
|
+
declare const DEFAULT_TARGET_LANG_LIST: string[];
|
|
275
277
|
/**
|
|
276
278
|
* 默认插件配置选项
|
|
277
279
|
*/
|
|
@@ -295,9 +297,9 @@ declare const DEFAULT_OPTION: {
|
|
|
295
297
|
distPath: string;
|
|
296
298
|
/** 打包后生成文件的主文件名称,默认是 'index' */
|
|
297
299
|
distKey: string;
|
|
298
|
-
/**
|
|
299
|
-
originLang:
|
|
300
|
-
/**
|
|
300
|
+
/** 来源语言,由插件固定使用默认值 */
|
|
301
|
+
originLang: string;
|
|
302
|
+
/** 翻译目标语言列表,由插件固定使用默认值 */
|
|
301
303
|
targetLangList: string[];
|
|
302
304
|
/** 语言key,用于请求谷歌api和生成配置文件下对应语言的内容文件 */
|
|
303
305
|
langKey: string[];
|
|
@@ -361,8 +363,7 @@ declare let option: OptionType;
|
|
|
361
363
|
/**
|
|
362
364
|
* 类型定义:用户传入的配置选项
|
|
363
365
|
*/
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
+
type OptionInfo = Partial<Omit<OptionType, 'originLang' | 'targetLangList' | 'langKey'>>;
|
|
366
367
|
/**
|
|
367
368
|
* 初始化插件配置选项
|
|
368
369
|
* @param optionInfo 用户提供的配置选项
|
|
@@ -387,9 +388,9 @@ declare function initOption(optionInfo: OptionInfo): {
|
|
|
387
388
|
distPath: string;
|
|
388
389
|
/** 打包后生成文件的主文件名称,默认是 'index' */
|
|
389
390
|
distKey: string;
|
|
390
|
-
/**
|
|
391
|
-
originLang:
|
|
392
|
-
/**
|
|
391
|
+
/** 来源语言,由插件固定使用默认值 */
|
|
392
|
+
originLang: string;
|
|
393
|
+
/** 翻译目标语言列表,由插件固定使用默认值 */
|
|
393
394
|
targetLangList: string[];
|
|
394
395
|
/** 语言key,用于请求谷歌api和生成配置文件下对应语言的内容文件 */
|
|
395
396
|
langKey: string[];
|
|
@@ -830,4 +831,4 @@ declare class webpackPluginsAutoI18n {
|
|
|
830
831
|
apply(compiler: webpack.Compiler): void;
|
|
831
832
|
}
|
|
832
833
|
|
|
833
|
-
export { BaiduTranslator, type BaiduTranslatorOption, type BaseExtendsType, CNToTWTranslator, EmptyTranslator, FunctionFactoryOption, GoogleTranslator, type GoogleTranslatorOption, type I18nLocaleMessages, type I18nManifestCollector, type I18nMessages, type I18nRuntime, type I18nRuntimeConfigPayload, type I18nRuntimeDeltaItem, type I18nRuntimeOptions, LanguageEnum, type ManifestRecordInput, type OptionInfo, OriginLangKeyEnum, RESOLVED_VITE_RUNTIME_MANIFEST_ID, RUNTIME_MANIFEST_GLOBAL, RUNTIME_MANIFEST_VERSION, type RuntimeManifest, type RuntimeManifestOptionLike, type RuntimeManifestRecord, type RuntimeManifestResource, ScanTranslator, TranslateApiEnum, TranslateTypeEnum, Translator, type TranslatorOption, VITE_RUNTIME_MANIFEST_ID, VolcengineTranslator, type VolcengineTranslatorOption, Vue2Extends, YoudaoTranslator, type YoudaoTranslatorOption, base as baseUtils, checkOption, createI18nManifestCollector, createI18nRuntime, webpackPluginsAutoI18n as default, file as fileUtils, index as filter, initOption, installI18nRuntime, option, runtimeUtils, serializeRuntimeManifest, translate as translateUtils, upload$1 as uploadUtils };
|
|
834
|
+
export { BaiduTranslator, type BaiduTranslatorOption, type BaseExtendsType, CNToTWTranslator, DEFAULT_ORIGIN_LANG, DEFAULT_TARGET_LANG_LIST, EmptyTranslator, FunctionFactoryOption, GoogleTranslator, type GoogleTranslatorOption, type I18nLocaleMessages, type I18nManifestCollector, type I18nMessages, type I18nRuntime, type I18nRuntimeConfigPayload, type I18nRuntimeDeltaItem, type I18nRuntimeOptions, LanguageEnum, type ManifestRecordInput, type OptionInfo, OriginLangKeyEnum, RESOLVED_VITE_RUNTIME_MANIFEST_ID, RUNTIME_MANIFEST_GLOBAL, RUNTIME_MANIFEST_VERSION, type RuntimeManifest, type RuntimeManifestOptionLike, type RuntimeManifestRecord, type RuntimeManifestResource, ScanTranslator, TranslateApiEnum, TranslateTypeEnum, Translator, type TranslatorOption, VITE_RUNTIME_MANIFEST_ID, VolcengineTranslator, type VolcengineTranslatorOption, Vue2Extends, YoudaoTranslator, type YoudaoTranslatorOption, base as baseUtils, checkOption, createI18nManifestCollector, createI18nRuntime, webpackPluginsAutoI18n as default, file as fileUtils, index as filter, initOption, installI18nRuntime, option, runtimeUtils, serializeRuntimeManifest, translate as translateUtils, upload$1 as uploadUtils };
|
package/dist/index.mjs
CHANGED
|
@@ -26,7 +26,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
26
26
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
27
27
|
PERFORMANCE OF THIS SOFTWARE.
|
|
28
28
|
***************************************************************************** */
|
|
29
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
29
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
30
30
|
|
|
31
31
|
var __assign = function () {
|
|
32
32
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -78,12 +78,8 @@ function __generator(thisArg, body) {
|
|
|
78
78
|
f,
|
|
79
79
|
y,
|
|
80
80
|
t,
|
|
81
|
-
g;
|
|
82
|
-
return g = {
|
|
83
|
-
next: verb(0),
|
|
84
|
-
"throw": verb(1),
|
|
85
|
-
"return": verb(2)
|
|
86
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
81
|
+
g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
82
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
87
83
|
return this;
|
|
88
84
|
}), g;
|
|
89
85
|
function verb(n) {
|
|
@@ -1450,7 +1446,12 @@ function hasOriginSymbols$1(value) {
|
|
|
1450
1446
|
const originRegex = REGEX_MAP[option.originLang];
|
|
1451
1447
|
return originRegex ? originRegex.test(value) : false;
|
|
1452
1448
|
}
|
|
1449
|
+
function isTemplateFragmentSegment(value) {
|
|
1450
|
+
return /[^\p{Script=Han}A-Za-z0-9_\s]/u.test(value);
|
|
1451
|
+
}
|
|
1453
1452
|
function getTemplateSemanticSplitSegments(value) {
|
|
1453
|
+
const expressionCount = value.match(/\$\{[^}]+}/g)?.length || 0;
|
|
1454
|
+
if (expressionCount < 2) return [];
|
|
1454
1455
|
const segments = value.split(/\$\{[^}]+}/g);
|
|
1455
1456
|
const result = new Set();
|
|
1456
1457
|
for (let index = 0; index < segments.length - 1; index++) {
|
|
@@ -1458,7 +1459,7 @@ function getTemplateSemanticSplitSegments(value) {
|
|
|
1458
1459
|
const afterValue = segments[index + 1];
|
|
1459
1460
|
if (!hasOriginSymbols$1(beforeValue) || !hasOriginSymbols$1(afterValue)) continue;
|
|
1460
1461
|
[beforeValue, afterValue].forEach(segment => {
|
|
1461
|
-
if (segment.trim().length > 1) {
|
|
1462
|
+
if (segment.trim().length > 1 && isTemplateFragmentSegment(segment)) {
|
|
1462
1463
|
result.add(segment);
|
|
1463
1464
|
}
|
|
1464
1465
|
});
|
|
@@ -2245,6 +2246,8 @@ let TranslateTypeEnum = /*#__PURE__*/function (TranslateTypeEnum) {
|
|
|
2245
2246
|
* @FilePath: /i18n_translation_vite/packages/autoI18nPluginCore/src/option.ts
|
|
2246
2247
|
*/
|
|
2247
2248
|
|
|
2249
|
+
const DEFAULT_ORIGIN_LANG = 'zh-cn';
|
|
2250
|
+
const DEFAULT_TARGET_LANG_LIST = ['zh-tw'];
|
|
2248
2251
|
const EXCLUDED_CALL = ['$deepScan', 'console.info', 'console.warn', 'console.error', '$i8n', 'console.log', '$t', 'require', '$$i8n', '$$t', '_createCommentVNode'];
|
|
2249
2252
|
/**
|
|
2250
2253
|
* 默认插件配置选项
|
|
@@ -2269,10 +2272,10 @@ const DEFAULT_OPTION = {
|
|
|
2269
2272
|
distPath: '',
|
|
2270
2273
|
/** 打包后生成文件的主文件名称,默认是 'index' */
|
|
2271
2274
|
distKey: 'index',
|
|
2272
|
-
/**
|
|
2273
|
-
originLang:
|
|
2274
|
-
/**
|
|
2275
|
-
targetLangList: [
|
|
2275
|
+
/** 来源语言,由插件固定使用默认值 */
|
|
2276
|
+
originLang: DEFAULT_ORIGIN_LANG,
|
|
2277
|
+
/** 翻译目标语言列表,由插件固定使用默认值 */
|
|
2278
|
+
targetLangList: [...DEFAULT_TARGET_LANG_LIST],
|
|
2276
2279
|
/** 语言key,用于请求谷歌api和生成配置文件下对应语言的内容文件 */
|
|
2277
2280
|
langKey: [],
|
|
2278
2281
|
/** 命名空间,防止全局命名冲突 */
|
|
@@ -2377,6 +2380,8 @@ function initOption(optionInfo) {
|
|
|
2377
2380
|
...DEFAULT_OPTION,
|
|
2378
2381
|
...generateUserOption(optionInfo)
|
|
2379
2382
|
};
|
|
2383
|
+
option.originLang = DEFAULT_ORIGIN_LANG;
|
|
2384
|
+
option.targetLangList = [...DEFAULT_TARGET_LANG_LIST];
|
|
2380
2385
|
|
|
2381
2386
|
// 初始化语言key数组,包含来源语言和目标语言
|
|
2382
2387
|
option.langKey = [option.originLang, ...option.targetLangList];
|
|
@@ -2946,7 +2951,7 @@ function StringLiteralFn (insertOption) {
|
|
|
2946
2951
|
|
|
2947
2952
|
// 防止导入语句,只处理那些当前节点不是键值对的键的字符串字面量,调用语句判断当前调用语句是否包含需要过滤的调用语句
|
|
2948
2953
|
if (isTranslateCall(parent) || types.isImportDeclaration(parent) || parent.key === node || types.isCallExpression(parent) && extractFnName && (option.excludedCall.includes(extractFnName) || extractFnName?.split('.')?.pop() && option.excludedCall.includes(extractFnName?.split('.')?.pop() || ''))) return;
|
|
2949
|
-
const
|
|
2954
|
+
const vueVNodeInfo = getVueCompiledVNodeInfo(path);
|
|
2950
2955
|
let replaceNode;
|
|
2951
2956
|
if (option.deepScan && checkNeedSplit(value)) {
|
|
2952
2957
|
replaceNode = convertToTemplateLiteral(splitByRegex(value, getOriginRegex()), insertOption);
|
|
@@ -2965,26 +2970,38 @@ function StringLiteralFn (insertOption) {
|
|
|
2965
2970
|
});
|
|
2966
2971
|
}
|
|
2967
2972
|
path.replaceWith(replaceNode);
|
|
2968
|
-
markVueCompiledVNodeDynamic(
|
|
2973
|
+
markVueCompiledVNodeDynamic(vueVNodeInfo?.callPath, vueVNodeInfo?.dynamicPropName);
|
|
2969
2974
|
}
|
|
2970
2975
|
};
|
|
2971
2976
|
}
|
|
2972
|
-
function
|
|
2977
|
+
function getVueCompiledVNodeInfo(path) {
|
|
2973
2978
|
const callPath = path.parentPath;
|
|
2974
|
-
if (
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2979
|
+
if (callPath && types.isCallExpression(callPath.node) && isVueVNodeCreateCall(callPath.node) && path.listKey === 'arguments' && path.key === 2) {
|
|
2980
|
+
return {
|
|
2981
|
+
callPath
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
const propertyPath = path.parentPath;
|
|
2985
|
+
const propsPath = propertyPath?.parentPath;
|
|
2986
|
+
const vnodeCallPath = propsPath?.parentPath;
|
|
2987
|
+
if (!propertyPath || !types.isObjectProperty(propertyPath.node) || propertyPath.node.value !== path.node || propertyPath.node.computed || !propsPath || !types.isObjectExpression(propsPath.node) || propsPath.listKey !== 'arguments' || propsPath.key !== 1 || !vnodeCallPath || !types.isCallExpression(vnodeCallPath.node) || !isVueVNodeCreateCall(vnodeCallPath.node)) return;
|
|
2988
|
+
const key = propertyPath.node.key;
|
|
2989
|
+
const dynamicPropName = types.isIdentifier(key) ? key.name : types.isStringLiteral(key) ? key.value : undefined;
|
|
2990
|
+
if (!dynamicPropName) return;
|
|
2991
|
+
return {
|
|
2992
|
+
callPath: vnodeCallPath,
|
|
2993
|
+
dynamicPropName
|
|
2994
|
+
};
|
|
2978
2995
|
}
|
|
2979
|
-
function markVueCompiledVNodeDynamic(callPath) {
|
|
2996
|
+
function markVueCompiledVNodeDynamic(callPath, dynamicPropName) {
|
|
2980
2997
|
if (!callPath || !types.isCallExpression(callPath.node)) return;
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2998
|
+
if (dynamicPropName) {
|
|
2999
|
+
markVueCompiledPropDynamic(callPath.node, dynamicPropName);
|
|
3000
|
+
} else {
|
|
3001
|
+
const patchFlag = callPath.node.arguments[3];
|
|
3002
|
+
if (isCachedPatchFlag(patchFlag)) {
|
|
3003
|
+
callPath.node.arguments[3] = createPatchFlag(1);
|
|
3004
|
+
}
|
|
2988
3005
|
}
|
|
2989
3006
|
const logicalPath = callPath.findParent(parentPath => {
|
|
2990
3007
|
const node = parentPath.node;
|
|
@@ -2996,6 +3013,33 @@ function markVueCompiledVNodeDynamic(callPath) {
|
|
|
2996
3013
|
logicalPath.replaceWith(callPath.node);
|
|
2997
3014
|
}
|
|
2998
3015
|
}
|
|
3016
|
+
function markVueCompiledPropDynamic(call, propName) {
|
|
3017
|
+
while (call.arguments.length < 3) {
|
|
3018
|
+
call.arguments.push(types.nullLiteral());
|
|
3019
|
+
}
|
|
3020
|
+
const patchFlag = call.arguments[3];
|
|
3021
|
+
if (!patchFlag || isCachedPatchFlag(patchFlag)) {
|
|
3022
|
+
call.arguments[3] = createPatchFlag(8);
|
|
3023
|
+
} else if (types.isNumericLiteral(patchFlag) && (patchFlag.value & 8) !== 8) {
|
|
3024
|
+
call.arguments[3] = createPatchFlag(patchFlag.value | 8);
|
|
3025
|
+
}
|
|
3026
|
+
const dynamicProps = call.arguments[4];
|
|
3027
|
+
if (types.isArrayExpression(dynamicProps)) {
|
|
3028
|
+
const hasProp = dynamicProps.elements.some(element => types.isStringLiteral(element) && element.value === propName);
|
|
3029
|
+
if (!hasProp) {
|
|
3030
|
+
dynamicProps.elements.push(types.stringLiteral(propName));
|
|
3031
|
+
}
|
|
3032
|
+
} else {
|
|
3033
|
+
call.arguments[4] = types.arrayExpression([types.stringLiteral(propName)]);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
function createPatchFlag(value) {
|
|
3037
|
+
const patchFlag = types.numericLiteral(value);
|
|
3038
|
+
patchFlag.leadingComments = null;
|
|
3039
|
+
patchFlag.innerComments = null;
|
|
3040
|
+
patchFlag.trailingComments = null;
|
|
3041
|
+
return patchFlag;
|
|
3042
|
+
}
|
|
2999
3043
|
function isCachedPatchFlag(node) {
|
|
3000
3044
|
return types.isNumericLiteral(node) && node.value === -1 || types.isUnaryExpression(node) && node.operator === '-' && types.isNumericLiteral(node.argument) && node.argument.value === 1;
|
|
3001
3045
|
}
|
|
@@ -3375,8 +3419,6 @@ var webpackPluginsAutoI18n = /** @class */function () {
|
|
|
3375
3419
|
translateKey: '$t',
|
|
3376
3420
|
distPath: './dist/assets',
|
|
3377
3421
|
distKey: 'index',
|
|
3378
|
-
targetLangList: ['zh-cn', 'zh-tw'],
|
|
3379
|
-
originLang: 'zh-cn',
|
|
3380
3422
|
translator: new CNToTWTranslator()
|
|
3381
3423
|
}, optionInfo));
|
|
3382
3424
|
// 检查配置有效性,如果无效则不执行后续逻辑
|
|
@@ -3545,5 +3587,5 @@ function generateAdvancedRegex(extensions) {
|
|
|
3545
3587
|
return new RegExp(finalRegex, 'i');
|
|
3546
3588
|
}
|
|
3547
3589
|
|
|
3548
|
-
export { BaiduTranslator, CNToTWTranslator, EmptyTranslator, FunctionFactoryOption, GoogleTranslator, LanguageEnum, OriginLangKeyEnum, RESOLVED_VITE_RUNTIME_MANIFEST_ID, RUNTIME_MANIFEST_GLOBAL, RUNTIME_MANIFEST_VERSION, ScanTranslator, TranslateApiEnum, TranslateTypeEnum, Translator, VITE_RUNTIME_MANIFEST_ID, VolcengineTranslator, Vue2Extends, YoudaoTranslator, base as baseUtils, checkOption, createI18nManifestCollector, createI18nRuntime, webpackPluginsAutoI18n as default, file as fileUtils, index$1 as filter, initOption, installI18nRuntime, option, runtimeUtils, serializeRuntimeManifest, translate as translateUtils, upload$1 as uploadUtils };
|
|
3590
|
+
export { BaiduTranslator, CNToTWTranslator, DEFAULT_ORIGIN_LANG, DEFAULT_TARGET_LANG_LIST, EmptyTranslator, FunctionFactoryOption, GoogleTranslator, LanguageEnum, OriginLangKeyEnum, RESOLVED_VITE_RUNTIME_MANIFEST_ID, RUNTIME_MANIFEST_GLOBAL, RUNTIME_MANIFEST_VERSION, ScanTranslator, TranslateApiEnum, TranslateTypeEnum, Translator, VITE_RUNTIME_MANIFEST_ID, VolcengineTranslator, Vue2Extends, YoudaoTranslator, base as baseUtils, checkOption, createI18nManifestCollector, createI18nRuntime, webpackPluginsAutoI18n as default, file as fileUtils, index$1 as filter, initOption, installI18nRuntime, option, runtimeUtils, serializeRuntimeManifest, translate as translateUtils, upload$1 as uploadUtils };
|
|
3549
3591
|
//# sourceMappingURL=index.mjs.map
|