vue-i18n-extract-plugin 1.0.66 → 1.0.67
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/README.md +1 -1
- package/lib/extract.js +3 -2
- package/lib/import-i18n-transform.js +5 -4
- package/lib/options.js +1 -1
- package/lib/utils.js +5 -0
- package/package.json +1 -1
- package/types/index.d.ts +2 -0
- package/types/options.d.ts +1 -1
- package/types/utils.d.ts +1 -0
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ const defaultOptions = {
|
|
|
64
64
|
excludedCall: [], // 排除的调用函数名称数组,目前已内置的函数请参阅:https://github.com/semdy/vue-i18n-extract-plugin/blob/main/lib/utils.js#L189
|
|
65
65
|
includePath: ['src/'], // 包含路径的数组
|
|
66
66
|
excludedPath: [], // 排除路径的数组 refer to https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#how-to-exclude-directory-from-reading
|
|
67
|
-
allowedExtensions: [".vue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
67
|
+
allowedExtensions: [".vue", ".nvue", ".uvue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
68
68
|
fromLang: 'zh-cn', // 源语言, 目前支持提取的语言有:zh-cn(zh-tw), en, ja, ko, ru
|
|
69
69
|
translateLangKeys: ["zh-tw", "en"], // 需要翻译为的语言键
|
|
70
70
|
i18nPkgImportPath: "@/i18n", // i18n语言包导入路径
|
package/lib/extract.js
CHANGED
|
@@ -23,7 +23,8 @@ const {
|
|
|
23
23
|
padEmptyLine,
|
|
24
24
|
isEmptyObject,
|
|
25
25
|
getLangJsonPath,
|
|
26
|
-
readJsonWithDefault
|
|
26
|
+
readJsonWithDefault,
|
|
27
|
+
isVueLike
|
|
27
28
|
} = require("./utils");
|
|
28
29
|
const { defaultOptions } = require("./options");
|
|
29
30
|
const { autoTranslate, cleanTranslate, cleanI18nMap } = require("./translate");
|
|
@@ -545,7 +546,7 @@ async function extractI18n(options) {
|
|
|
545
546
|
if (!content.trim()) continue;
|
|
546
547
|
|
|
547
548
|
try {
|
|
548
|
-
if (file
|
|
549
|
+
if (isVueLike(file)) {
|
|
549
550
|
const vueContent = processVueFile(content, options);
|
|
550
551
|
changed = vueContent.changed;
|
|
551
552
|
code = vueContent.code;
|
|
@@ -2,6 +2,7 @@ const parser = require("@babel/parser");
|
|
|
2
2
|
const traverse = require("@babel/traverse").default;
|
|
3
3
|
const generate = require("@babel/generator").default;
|
|
4
4
|
const t = require("@babel/types");
|
|
5
|
+
const { isVueLike } = require("./utils");
|
|
5
6
|
|
|
6
7
|
function i18nImportAstTransform(ast, importName, importPath) {
|
|
7
8
|
let hasI18nImport = false;
|
|
@@ -89,7 +90,7 @@ function i18nImportAstTransform(ast, importName, importPath) {
|
|
|
89
90
|
} else {
|
|
90
91
|
ast.program.body.unshift(importNode);
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
|
|
93
94
|
needTransform = true;
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -109,7 +110,7 @@ async function i18nImportTransform(code, path, importNames, importPath) {
|
|
|
109
110
|
plugins: [
|
|
110
111
|
"typescript",
|
|
111
112
|
"jsx",
|
|
112
|
-
path
|
|
113
|
+
isVueLike(path) ? "topLevelAwait" : null
|
|
113
114
|
].filter(Boolean)
|
|
114
115
|
});
|
|
115
116
|
|
|
@@ -127,7 +128,7 @@ async function i18nImportTransform(code, path, importNames, importPath) {
|
|
|
127
128
|
// 只有当需要修改时才重新生成代码
|
|
128
129
|
if (transformNeeded) {
|
|
129
130
|
const { code: newScript } = generate(ast);
|
|
130
|
-
return path
|
|
131
|
+
return isVueLike(path)
|
|
131
132
|
? code.replace(scriptContent, newScript)
|
|
132
133
|
: newScript;
|
|
133
134
|
}
|
|
@@ -139,7 +140,7 @@ async function i18nImportTransform(code, path, importNames, importPath) {
|
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
function extractScriptContent(code, path) {
|
|
142
|
-
if (!path
|
|
143
|
+
if (!isVueLike(path)) return code;
|
|
143
144
|
const scriptMatch = code.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);
|
|
144
145
|
return scriptMatch?.[1] || "";
|
|
145
146
|
}
|
package/lib/options.js
CHANGED
|
@@ -18,7 +18,7 @@ const defaultOptions = {
|
|
|
18
18
|
excludedCall: [], // 排除的调用函数名称数组
|
|
19
19
|
includePath: ["src/"], // 包含路径的数组
|
|
20
20
|
excludedPath: [], // 排除路径的数组
|
|
21
|
-
allowedExtensions: [".vue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
21
|
+
allowedExtensions: [".vue", ".nvue", ".uvue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
22
22
|
fromLang: "zh-cn", // 源语言, 目前支持提取的语言有:zh-cn(zh-tw), en, ja, ko, ru
|
|
23
23
|
translateLangKeys: ["zh-tw", "en"], // 需要翻译为的语言键
|
|
24
24
|
i18nPkgImportPath: "@/i18n", // i18n语言包导入路径
|
package/lib/utils.js
CHANGED
|
@@ -46,6 +46,10 @@ function isEmptyObject(obj) {
|
|
|
46
46
|
return Object.keys(obj).length === 0;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
function isVueLike(filePath) {
|
|
50
|
+
return /\.(vue|nvue|uvue)$/.test(filePath);
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
function checkAgainstRegexArray(value, regexArray = []) {
|
|
50
54
|
for (let i = 0; i < regexArray.length; i++) {
|
|
51
55
|
const regex =
|
|
@@ -259,6 +263,7 @@ module.exports = {
|
|
|
259
263
|
generateId,
|
|
260
264
|
parseArg,
|
|
261
265
|
isEmptyObject,
|
|
266
|
+
isVueLike,
|
|
262
267
|
checkAgainstRegexArray,
|
|
263
268
|
extractFunctionName,
|
|
264
269
|
relativeCWDPath,
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
package/types/options.d.ts
CHANGED
package/types/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export function hashKey(str: string): string;
|
|
|
5
5
|
export function generateId(text: string, length?: number): string;
|
|
6
6
|
export function parseArg(arg: string): any;
|
|
7
7
|
export function isEmptyObject(obj: Record<string, any>): boolean;
|
|
8
|
+
export function isVueLike(filePath: string): boolean;
|
|
8
9
|
export function checkAgainstRegexArray(value: string, regexArray?: (string | RegExp)[]): boolean;
|
|
9
10
|
export function extractFunctionName(path: NodePath): string;
|
|
10
11
|
export function relativeCWDPath(subPath: string): string;
|