vue-i18n-extract-plugin 1.0.55 → 1.0.56
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 -0
- package/lib/options.js +1 -0
- package/lib/visitors.js +14 -7
- package/package.json +1 -1
- package/types/options.d.ts +1 -0
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ const defaultOptions = {
|
|
|
63
63
|
includePath: ['src/'], // 包含路径的数组
|
|
64
64
|
excludedPath: [], // 排除路径的数组 refer to https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#how-to-exclude-directory-from-reading
|
|
65
65
|
allowedExtensions: [".vue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
66
|
+
generateId: null, // 自定义生成 key 的函数
|
|
66
67
|
fromLang: 'zh-cn', // 源语言, 目前支持提取的语言有:zh-cn(zh-tw), en, ja, ko, ru
|
|
67
68
|
translateLangKeys: ["zh-tw", "en"], // 需要翻译为的语言键
|
|
68
69
|
i18nPkgImportPath: "@/i18n", // i18n语言包导入路径
|
package/lib/options.js
CHANGED
|
@@ -17,6 +17,7 @@ const defaultOptions = {
|
|
|
17
17
|
includePath: ["src/"], // 包含路径的数组
|
|
18
18
|
excludedPath: [], // 排除路径的数组
|
|
19
19
|
allowedExtensions: [".vue", ".tsx", ".ts", ".jsx", ".js"], // 允许提取的文件扩展名
|
|
20
|
+
generateId: null, // 自定义生成 key 的函数
|
|
20
21
|
fromLang: "zh-cn", // 源语言, 目前支持提取的语言有:zh-cn(zh-tw), en, ja, ko, ru
|
|
21
22
|
translateLangKeys: ["zh-tw", "en"], // 需要翻译为的语言键
|
|
22
23
|
i18nPkgImportPath: "@/i18n", // i18n语言包导入路径
|
package/lib/visitors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const t = require("@babel/types");
|
|
2
2
|
const {
|
|
3
|
-
generateId,
|
|
3
|
+
generateId: _generateId,
|
|
4
4
|
extractFunctionName,
|
|
5
5
|
EXCLUDED_CALL,
|
|
6
6
|
shouldExtract
|
|
@@ -129,6 +129,13 @@ function generateText(rawText, hashedText, options) {
|
|
|
129
129
|
return hashedText;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
function generateId(rawText, options) {
|
|
133
|
+
if (typeof options.generateId === "function") {
|
|
134
|
+
return options.generateId(rawText);
|
|
135
|
+
}
|
|
136
|
+
return _generateId(rawText);
|
|
137
|
+
}
|
|
138
|
+
|
|
132
139
|
function createI18nVisitor(option, i18nMap) {
|
|
133
140
|
const excludedCall = [...option.excludedCall, ...EXCLUDED_CALL];
|
|
134
141
|
|
|
@@ -153,7 +160,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
153
160
|
return;
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
const hashed = generateId(keyText);
|
|
163
|
+
const hashed = generateId(keyText, option);
|
|
157
164
|
|
|
158
165
|
if (i18nMap) {
|
|
159
166
|
i18nMap[hashed] = keyText;
|
|
@@ -208,7 +215,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
208
215
|
return;
|
|
209
216
|
}
|
|
210
217
|
|
|
211
|
-
const hashed = generateId(value);
|
|
218
|
+
const hashed = generateId(value, option);
|
|
212
219
|
|
|
213
220
|
if (i18nMap) {
|
|
214
221
|
i18nMap[hashed] = value;
|
|
@@ -288,7 +295,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
288
295
|
|
|
289
296
|
if (option.extractFromText === false) return;
|
|
290
297
|
|
|
291
|
-
const hashed = generateId(value);
|
|
298
|
+
const hashed = generateId(value, option);
|
|
292
299
|
|
|
293
300
|
if (i18nMap) {
|
|
294
301
|
i18nMap[hashed] = value;
|
|
@@ -309,7 +316,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
309
316
|
return;
|
|
310
317
|
}
|
|
311
318
|
|
|
312
|
-
const hashed = generateId(text);
|
|
319
|
+
const hashed = generateId(text, option);
|
|
313
320
|
|
|
314
321
|
if (i18nMap) {
|
|
315
322
|
i18nMap[hashed] = text;
|
|
@@ -337,7 +344,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
337
344
|
return;
|
|
338
345
|
}
|
|
339
346
|
|
|
340
|
-
const hashed = generateId(value);
|
|
347
|
+
const hashed = generateId(value, option);
|
|
341
348
|
|
|
342
349
|
if (i18nMap) {
|
|
343
350
|
i18nMap[hashed] = value;
|
|
@@ -386,7 +393,7 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
386
393
|
|
|
387
394
|
// 计算 id,如果未提供,则使用 defaultMsg 的哈希值
|
|
388
395
|
if (!idValue && defaultMsgValue) {
|
|
389
|
-
idValue = generateId(defaultMsgValue);
|
|
396
|
+
idValue = generateId(defaultMsgValue, option);
|
|
390
397
|
|
|
391
398
|
if (i18nMap) {
|
|
392
399
|
i18nMap[idValue] = defaultMsgValue;
|
package/package.json
CHANGED
package/types/options.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface I18nOptions {
|
|
|
19
19
|
translateLangKeys: LangKey[]
|
|
20
20
|
i18nPkgImportPath: string
|
|
21
21
|
outputPath: string
|
|
22
|
+
generateId: ((text: string) => string) | null | undefined
|
|
22
23
|
customGenLangFileName: (langKey: LangKey) => LangKey
|
|
23
24
|
customTranslatedText: (text: string, toLang: LangKey) => string,
|
|
24
25
|
// translator: new GoogleTranslator({
|