rsbuild-auto-i18n-plugin 1.1.10 → 1.1.11

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/index.cjs CHANGED
@@ -94,9 +94,9 @@ function rsbuildPluginsAutoI18n(optionInfo) {
94
94
  configFile: false,
95
95
  plugins: [autoI18nPluginCore.filter.default(sourceObj)]
96
96
  });
97
- // 开发模式下执行实时翻译
97
+ // 开发模式下:改为批量防抖调用,避免每次 transform 都触发完整翻译流程与重复输出
98
98
  if (isDevMode) {
99
- autoI18nPluginCore.translateUtils.autoTranslate(); // 执行前需要确保transformAsync已经完成
99
+ autoI18nPluginCore.translateUtils.scheduleAutoTranslate(resourcePath);
100
100
  }
101
101
  return {
102
102
  code: result?.code || code
@@ -108,27 +108,28 @@ function rsbuildPluginsAutoI18n(optionInfo) {
108
108
  };
109
109
  }
110
110
  });
111
- // 构建开始前
111
+ // 构建开始前(保留简短提示或可删除)
112
112
  api.onBeforeBuild(() => {
113
113
  console.info('Rsbuild 构建阶段批量翻译开始');
114
114
  });
115
- // 构建结束后
115
+ // 构建结束后:批量翻译并统一输出
116
116
  api.onAfterBuild(async () => {
117
- console.info('构建阶段批量翻译');
118
- await autoI18nPluginCore.translateUtils.autoTranslate();
117
+ await autoI18nPluginCore.translateUtils.runAutoTranslateBatch();
119
118
  });
120
- // 构建完全结束
119
+ // 构建完全结束:清理并按需写入主文件(避免空写入)
121
120
  api.onCloseBuild(async () => {
122
121
  autoI18nPluginCore.translateUtils.cleanupUnusedTranslations();
123
- // 翻译配置写入主文件
124
- await autoI18nPluginCore.fileUtils.buildSetLangConfigToIndexFile();
125
- console.info('翻译完成✔');
122
+ if (autoI18nPluginCore.translateUtils.hasTranslationChanges) {
123
+ await autoI18nPluginCore.fileUtils.buildSetLangConfigToIndexFile();
124
+ }
125
+ // 不在此处重复打印“翻译完成”,已由 runAutoTranslateBatch 统一输出
126
126
  });
127
- // 开发服务器关闭时也需要清理
127
+ // 开发服务器关闭时也需要清理并按需写入
128
128
  api.onCloseDevServer(async () => {
129
129
  autoI18nPluginCore.translateUtils.cleanupUnusedTranslations();
130
- await autoI18nPluginCore.fileUtils.buildSetLangConfigToIndexFile();
131
- console.info('开发服务器关闭,翻译完成✔');
130
+ if (autoI18nPluginCore.translateUtils.hasTranslationChanges) {
131
+ await autoI18nPluginCore.fileUtils.buildSetLangConfigToIndexFile();
132
+ }
132
133
  });
133
134
  }
134
135
  };
package/dist/index.mjs CHANGED
@@ -72,9 +72,9 @@ function rsbuildPluginsAutoI18n(optionInfo) {
72
72
  configFile: false,
73
73
  plugins: [filter.default(sourceObj)]
74
74
  });
75
- // 开发模式下执行实时翻译
75
+ // 开发模式下:改为批量防抖调用,避免每次 transform 都触发完整翻译流程与重复输出
76
76
  if (isDevMode) {
77
- translateUtils.autoTranslate(); // 执行前需要确保transformAsync已经完成
77
+ translateUtils.scheduleAutoTranslate(resourcePath);
78
78
  }
79
79
  return {
80
80
  code: result?.code || code
@@ -86,27 +86,28 @@ function rsbuildPluginsAutoI18n(optionInfo) {
86
86
  };
87
87
  }
88
88
  });
89
- // 构建开始前
89
+ // 构建开始前(保留简短提示或可删除)
90
90
  api.onBeforeBuild(() => {
91
91
  console.info('Rsbuild 构建阶段批量翻译开始');
92
92
  });
93
- // 构建结束后
93
+ // 构建结束后:批量翻译并统一输出
94
94
  api.onAfterBuild(async () => {
95
- console.info('构建阶段批量翻译');
96
- await translateUtils.autoTranslate();
95
+ await translateUtils.runAutoTranslateBatch();
97
96
  });
98
- // 构建完全结束
97
+ // 构建完全结束:清理并按需写入主文件(避免空写入)
99
98
  api.onCloseBuild(async () => {
100
99
  translateUtils.cleanupUnusedTranslations();
101
- // 翻译配置写入主文件
102
- await fileUtils.buildSetLangConfigToIndexFile();
103
- console.info('翻译完成✔');
100
+ if (translateUtils.hasTranslationChanges) {
101
+ await fileUtils.buildSetLangConfigToIndexFile();
102
+ }
103
+ // 不在此处重复打印“翻译完成”,已由 runAutoTranslateBatch 统一输出
104
104
  });
105
- // 开发服务器关闭时也需要清理
105
+ // 开发服务器关闭时也需要清理并按需写入
106
106
  api.onCloseDevServer(async () => {
107
107
  translateUtils.cleanupUnusedTranslations();
108
- await fileUtils.buildSetLangConfigToIndexFile();
109
- console.info('开发服务器关闭,翻译完成✔');
108
+ if (translateUtils.hasTranslationChanges) {
109
+ await fileUtils.buildSetLangConfigToIndexFile();
110
+ }
110
111
  });
111
112
  }
112
113
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-auto-i18n-plugin",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "Rsbuild automatic translation plugin compatible with Rspack",
5
5
  "keywords": [
6
6
  "i18n",
@@ -34,7 +34,7 @@
34
34
  "@babel/core": "^7.23.2",
35
35
  "@babel/preset-env": "^7.23.2",
36
36
  "@babel/preset-typescript": "^7.23.2",
37
- "auto-i18n-plugin-core": "1.1.10"
37
+ "auto-i18n-plugin-core": "1.1.11"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@babel/types": "^7.23.0",
@@ -53,6 +53,9 @@
53
53
  "peerDependencies": {
54
54
  "@rsbuild/core": ">=1.0.0"
55
55
  },
56
+ "volta": {
57
+ "extends": "../../package.json"
58
+ },
56
59
  "scripts": {
57
60
  "build": "rollup -c ./rollup.config.ts --configPlugin typescript"
58
61
  }
package/readme-en.md CHANGED
@@ -32,7 +32,7 @@ pnpm run preview // Don't select React, contains too much English text
32
32
  ## 📖 Supported Features
33
33
 
34
34
  - **Frameworks**: All JavaScript-based frontend frameworks (Vue2/3, React, etc.)
35
- - **Build Tools**: Fully compatible with Webpack, Vite, and Rollup 🚀
35
+ - **Build Tools**: Fully compatible with Webpack, Vite, Rsbuild and Rollup 🚀
36
36
  - **Translation Services**: Default support for **Youdao** and **Google** translation, plus custom translators
37
37
 
38
38
  ---
@@ -63,6 +63,14 @@ npm install webpack-auto-i18n-plugin --save-dev
63
63
  yarn add webpack-auto-i18n-plugin --dev
64
64
  ```
65
65
 
66
+ #### **⚡ Rsbuild Project:**
67
+
68
+ ```bash
69
+ npm install rsbuild-auto-i18n-plugin --save-dev
70
+ # 或
71
+ yarn add rsbuild-auto-i18n-plugin --dev
72
+ ```
73
+
66
74
  ---
67
75
 
68
76
  ### 2️⃣ Language Switching 🌐
@@ -191,13 +199,32 @@ module.exports = {
191
199
  }
192
200
  ```
193
201
 
202
+ #### **Rsbuild Configuration Example** (rsbuild.config.js):
203
+
204
+ ````javascript
205
+ const rsbuildPluginsAutoI18n = require('rsbuild-auto-i18n-plugin')
206
+ const { YoudaoTranslator } = require('rsbuild-auto-i18n-plugin')
207
+
208
+ export default defineConfig({
209
+ plugins: [
210
+ pluginReact(),
211
+ rsbuildPluginsAutoI18n({
212
+ targetLangList: ['en'],
213
+ translator: new YoudaoTranslator({
214
+ appId: '4cdb9baea8066fef',
215
+ appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
216
+ })
217
+ })
218
+ ],
219
+ });
220
+
194
221
  ---
195
222
 
196
223
  ### 4️⃣ Translator Configuration Examples 🛠️
197
224
 
198
225
  The plugin uses Google Translate by default (with a default proxy port of 7890). When the network does not support accessing Google, we recommend using **Youdao Translate** ✨, which has excellent translation quality. Currently, the plugin has built - in support for Google, Youdao, and Baidu translation services. If you need to customize a translator, you can refer to the examples below.
199
226
 
200
- The following examples use `vite` as an example, and `webpack` is similar.
227
+ The following examples use `vite` as an example, and `webpack`、`rsbuild` is similar.
201
228
 
202
229
  #### **Using Google Translate (Default)**
203
230
 
@@ -215,7 +242,7 @@ translator: new GoogleTranslator({
215
242
  }
216
243
  })
217
244
  ...
218
- ```
245
+ ````
219
246
 
220
247
  #### **Using Youdao Translation**
221
248
 
@@ -479,6 +506,10 @@ Since v1.0.5, simply import the generated `index.js` in your entry file - no nee
479
506
 
480
507
  Original authors: wenps, xu-code, Caleb-Xu, Winfans
481
508
 
509
+ ### v1.1.10 (Recommended Version)
510
+
511
+ - Added rsbuild plugin
512
+
482
513
  ## Changelog
483
514
 
484
515
  ### v1.1.9 (Recommended Version)
package/readme.md CHANGED
@@ -34,7 +34,7 @@ tips:有道翻译需要用户自己去申请有道的翻译服务,demo里面
34
34
  ## 📖 支持范围
35
35
 
36
36
  - **框架**: 支持所有编译为 JS 的前端框架(如 Vue2/3 和 React 等)。
37
- - **构建工具**: 完美兼容 Webpack、Vite 和 Rollup 🚀。
37
+ - **构建工具**: 完美兼容 Webpack、Vite、Rsbuild 和 Rollup 🚀。
38
38
  - **翻译服务**: 默认支持 **有道翻译** 和 **谷歌翻译**,并支持自定义翻译器。
39
39
 
40
40
  ---
@@ -65,6 +65,14 @@ npm install webpack-auto-i18n-plugin --save-dev
65
65
  yarn add webpack-auto-i18n-plugin --dev
66
66
  ```
67
67
 
68
+ #### **⚡ Rsbuild 项目:**
69
+
70
+ ```bash
71
+ npm install rsbuild-auto-i18n-plugin --save-dev
72
+ # 或
73
+ yarn add rsbuild-auto-i18n-plugin --dev
74
+ ```
75
+
68
76
  ---
69
77
 
70
78
  ### 2️⃣ 语言切换 🌐
@@ -193,13 +201,33 @@ module.exports = {
193
201
  }
194
202
  ```
195
203
 
204
+ #### **Rsbuild 配置示例** (rsbuild.config.js):
205
+
206
+ ```javascript
207
+ const rsbuildPluginsAutoI18n = require('rsbuild-auto-i18n-plugin')
208
+ const { YoudaoTranslator } = require('rsbuild-auto-i18n-plugin')
209
+
210
+ export default defineConfig({
211
+ plugins: [
212
+ pluginReact(),
213
+ rsbuildPluginsAutoI18n({
214
+ targetLangList: ['en'],
215
+ translator: new YoudaoTranslator({
216
+ appId: '4cdb9baea8066fef',
217
+ appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
218
+ })
219
+ })
220
+ ]
221
+ })
222
+ ```
223
+
196
224
  ---
197
225
 
198
226
  ### 4️⃣ 翻译器配置示例 🛠️
199
227
 
200
228
  插件默认使用谷歌翻译(默认配置代理端口7890)。在网络不支持访问谷歌的情况下,我们推荐使用 **有道翻译** ✨,其翻译效果优秀。目前插件已经内置谷歌、有道和百度翻译功能。如果需要自定义翻译器,可参考下方的示例。
201
229
 
202
- 以下示例以 `vite` 为例,`webpack` 与其类似。
230
+ 以下示例以 `vite` 为例,`webpack`、`rsbuild` 与其类似。
203
231
 
204
232
  #### **使用谷歌翻译(默认)**
205
233
 
@@ -485,6 +513,10 @@ const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
485
513
 
486
514
  ## 更新日志
487
515
 
516
+ ### v1.1.10 (推荐版本)
517
+
518
+ - 新增 rsbuild 插件
519
+
488
520
  ### v1.1.9 (推荐版本)
489
521
 
490
522
  - 修复 deepScan 切分字符串不处理换行符等问题