vue-i18n-extract-plugin 1.0.47 → 1.0.48

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 CHANGED
@@ -48,7 +48,7 @@ extractI18n(options)
48
48
  ```javascript
49
49
  const defaultOptions = {
50
50
  translateKey: "$t", // 提取的函数的名称
51
- rewrite: true, // 是否将提取到的内容转换为id后重写入源文件
51
+ rewrite: false, // 是否将提取到的内容转换为id后重写入源文件
52
52
  extractFromText: true, // 是否允许从纯文本节点中提取翻译内容
53
53
  autoImportI18n: true, // 是否自动导入 i18n 模块
54
54
  autoTranslate: true, // 提取完成后是否自动翻译
package/lib/cli.js CHANGED
@@ -38,7 +38,7 @@ const cli = async function (args) {
38
38
  name: Object.keys(bin)[0]
39
39
  });
40
40
 
41
- options = Object.assign({ rewrite: false }, configFromFile, options);
41
+ options = Object.assign({}, configFromFile, options);
42
42
 
43
43
  console.log("开始提取国际化内容...\n", options);
44
44
 
package/lib/options.js CHANGED
@@ -2,7 +2,7 @@ const { GoogleTranslator } = require("./translators");
2
2
 
3
3
  const defaultOptions = {
4
4
  translateKey: "$t", // 提取的函数的名称
5
- rewrite: true, // 是否将提取到的内容转换为id后重写入源文件
5
+ rewrite: false, // 是否将提取到的内容转换为id后重写入源文件
6
6
  extractFromText: true, // 是否允许从纯文本节点中提取翻译内容
7
7
  autoImportI18n: true, // 是否自动导入 i18n 模块
8
8
  autoTranslate: true, // 提取完成后是否自动翻译
package/lib/visitors.js CHANGED
@@ -58,10 +58,8 @@ function createI18nVisitor(option, i18nMap) {
58
58
  i18nMap[hashed] = keyText;
59
59
  }
60
60
 
61
- if (option.rewrite) {
62
- const newArg = t.stringLiteral(hashed);
63
- path.node.arguments[0] = newArg;
64
- }
61
+ const newArg = t.stringLiteral(hashed);
62
+ path.node.arguments[0] = newArg;
65
63
  },
66
64
 
67
65
  StringLiteral(path) {
@@ -113,19 +111,17 @@ function createI18nVisitor(option, i18nMap) {
113
111
  i18nMap[hashed] = value;
114
112
  }
115
113
 
116
- if (option.rewrite) {
117
- const callExpression = t.callExpression(
118
- t.identifier(option.translateKey),
119
- [t.stringLiteral(hashed)]
120
- );
121
- // 如果是 JSX 属性值,需要包裹在 JSXExpressionContainer 中
122
- if (parentPath.isJSXAttribute()) {
123
- const jsxExpression = t.jsxExpressionContainer(callExpression);
124
- path.replaceWith(jsxExpression);
125
- } else {
126
- // 其他情况直接替换
127
- path.replaceWith(callExpression);
128
- }
114
+ const callExpression = t.callExpression(
115
+ t.identifier(option.translateKey),
116
+ [t.stringLiteral(hashed)]
117
+ );
118
+ // 如果是 JSX 属性值,需要包裹在 JSXExpressionContainer 中
119
+ if (parentPath.isJSXAttribute()) {
120
+ const jsxExpression = t.jsxExpressionContainer(callExpression);
121
+ path.replaceWith(jsxExpression);
122
+ } else {
123
+ // 其他情况直接替换
124
+ path.replaceWith(callExpression);
129
125
  }
130
126
  },
131
127
 
@@ -163,11 +159,9 @@ function createI18nVisitor(option, i18nMap) {
163
159
  i18nMap[hashed] = value;
164
160
  }
165
161
 
166
- if (option.rewrite) {
167
- // 替换为字符类型翻译节点
168
- const tCallExpression = `${option.translateKey}('${hashed}')`;
169
- node.value.raw = node.value.cooked = `\${${tCallExpression}}`;
170
- }
162
+ // 替换为字符类型翻译节点
163
+ const tCallExpression = `${option.translateKey}('${hashed}')`;
164
+ node.value.raw = node.value.cooked = `\${${tCallExpression}}`;
171
165
  },
172
166
  JSXText(path) {
173
167
  // <div>Hello world</div>
@@ -188,16 +182,14 @@ function createI18nVisitor(option, i18nMap) {
188
182
  i18nMap[hashed] = text;
189
183
  }
190
184
 
191
- if (option.rewrite) {
192
- // 替换为表达式 {$t("hashed")}
193
- path.replaceWith(
194
- t.jsxExpressionContainer(
195
- t.callExpression(t.identifier(option.translateKey), [
196
- t.stringLiteral(hashed)
197
- ])
198
- )
199
- );
200
- }
185
+ // 替换为表达式 {$t("hashed")}
186
+ path.replaceWith(
187
+ t.jsxExpressionContainer(
188
+ t.callExpression(t.identifier(option.translateKey), [
189
+ t.stringLiteral(hashed)
190
+ ])
191
+ )
192
+ );
201
193
  },
202
194
  JSXExpressionContainer(path) {
203
195
  // <div>{"Hi"}</div>
@@ -216,15 +208,13 @@ function createI18nVisitor(option, i18nMap) {
216
208
  i18nMap[hashed] = expr.value;
217
209
  }
218
210
 
219
- if (option.rewrite) {
220
- path.replaceWith(
221
- t.jsxExpressionContainer(
222
- t.callExpression(t.identifier(option.translateKey), [
223
- t.stringLiteral(hashed)
224
- ])
225
- )
226
- );
227
- }
211
+ path.replaceWith(
212
+ t.jsxExpressionContainer(
213
+ t.callExpression(t.identifier(option.translateKey), [
214
+ t.stringLiteral(hashed)
215
+ ])
216
+ )
217
+ );
228
218
  }
229
219
  }
230
220
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-i18n-extract-plugin",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "main": "lib/index.js",
5
5
  "bin": {
6
6
  "extract-i18n": "lib/cli.js"