auto-i18n-plugin-core 1.1.8 → 1.1.10
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme-en.md +41 -30
- package/readme.md +32 -28
package/package.json
CHANGED
package/readme-en.md
CHANGED
|
@@ -41,7 +41,6 @@ pnpm run preview // Don't select React, contains too much English text
|
|
|
41
41
|
|
|
42
42
|
[Documentation](https://juejin.cn/post/7483435518526062626).
|
|
43
43
|
|
|
44
|
-
|
|
45
44
|
---
|
|
46
45
|
|
|
47
46
|
## 🌟 Quick Start 🚀
|
|
@@ -85,6 +84,7 @@ const langMap = {
|
|
|
85
84
|
#### 📲 Instant Language Switching
|
|
86
85
|
|
|
87
86
|
If you don't want to switch languages by refreshing the page, you can directly modify the language via `$changeLang` and then re - render the corresponding components.
|
|
87
|
+
|
|
88
88
|
```js
|
|
89
89
|
window.$changeLang('en')
|
|
90
90
|
```
|
|
@@ -118,17 +118,18 @@ export default {
|
|
|
118
118
|
}
|
|
119
119
|
</script>
|
|
120
120
|
```
|
|
121
|
+
|
|
121
122
|
#### 🔄 Replace Language Packs
|
|
122
123
|
|
|
123
124
|
If you want to modify the built - in generated language packs, you can directly modify the `langMap` in the global object. For example:
|
|
124
125
|
|
|
125
126
|
```js
|
|
126
127
|
window.langMap = {
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
en: {
|
|
129
|
+
zccsau6: 'hello'
|
|
129
130
|
},
|
|
130
131
|
'zh-cn': {
|
|
131
|
-
|
|
132
|
+
zccsau6: '你好'
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
```
|
|
@@ -165,6 +166,7 @@ export default defineConfig({
|
|
|
165
166
|
]
|
|
166
167
|
})
|
|
167
168
|
```
|
|
169
|
+
|
|
168
170
|
#### **Webpack Configuration Example** (webpack.config.js):
|
|
169
171
|
|
|
170
172
|
```javascript
|
|
@@ -190,6 +192,7 @@ module.exports = {
|
|
|
190
192
|
```
|
|
191
193
|
|
|
192
194
|
---
|
|
195
|
+
|
|
193
196
|
### 4️⃣ Translator Configuration Examples 🛠️
|
|
194
197
|
|
|
195
198
|
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.
|
|
@@ -213,9 +216,11 @@ translator: new GoogleTranslator({
|
|
|
213
216
|
})
|
|
214
217
|
...
|
|
215
218
|
```
|
|
219
|
+
|
|
216
220
|
#### **Using Youdao Translation**
|
|
217
221
|
|
|
218
222
|
You need to apply for an API. [API documentation](https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html).
|
|
223
|
+
|
|
219
224
|
```javascript
|
|
220
225
|
import { YoudaoTranslator } from 'vite-auto-i18n-plugin'
|
|
221
226
|
|
|
@@ -247,6 +252,7 @@ translator: new BaiduTranslator({
|
|
|
247
252
|
It supports translation using `doubao` or `deepseek`. The translation effect of large AI models is more accurate than traditional API translation, but it takes longer.
|
|
248
253
|
Introduction to Volcengine large models: https://www.volcengine.com/docs/82379/1099455.
|
|
249
254
|
You need to activate the large model service and apply for an API. [API documentation](https://www.volcengine.com/docs/82379/1298454).
|
|
255
|
+
|
|
250
256
|
```javascript
|
|
251
257
|
import { VolcengineTranslator } from 'vite-auto-i18n-plugin'
|
|
252
258
|
|
|
@@ -269,6 +275,7 @@ import { EmptyTranslator } from 'vite-auto-i18n-plugin'
|
|
|
269
275
|
translator: new EmptyTranslator()
|
|
270
276
|
...
|
|
271
277
|
```
|
|
278
|
+
|
|
272
279
|
#### **Custom Translator**
|
|
273
280
|
|
|
274
281
|
If you have a personal translation API, you can customize a translator in the following ways:
|
|
@@ -294,7 +301,9 @@ translator: new Translator({
|
|
|
294
301
|
})
|
|
295
302
|
...
|
|
296
303
|
```
|
|
304
|
+
|
|
297
305
|
If you need more advanced features, you can use inheritance. However, there is currently no relevant scenario.
|
|
306
|
+
|
|
298
307
|
```javascript
|
|
299
308
|
import { Translator } from 'vite-auto-i18n-plugin'
|
|
300
309
|
|
|
@@ -326,30 +335,30 @@ import '../lang/index.js' // 📍 Must be imported on the first line of the entr
|
|
|
326
335
|
|
|
327
336
|
## ⚙️ Configuration Parameters
|
|
328
337
|
|
|
329
|
-
| Parameter | Type | Required | Default | Description
|
|
330
|
-
| -------------------- | ---------- | -------- | ------------------------ |
|
|
331
|
-
| enabled | boolean | ❌ | `true` | Whether to trigger translation.
|
|
332
|
-
| translateType | string | ❌ | `full-auto` | Translation mode: `full-auto` or `semi-auto`
|
|
333
|
-
| translateKey | string | ✅ | `$t` | Translation function name (e.g., `$t`)
|
|
334
|
-
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | Function calls to exclude from translation
|
|
335
|
-
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | Patterns to exclude (e.g., file extensions)
|
|
336
|
-
| excludedPath | string[] | ❌ | `['node_modules']` | Directories to exclude (e.g., `node_modules`)
|
|
337
|
-
| includePath | RegExp[] | ❌ | `[/src\//]` | Whitelist of directories to include (default: `src`)
|
|
338
|
-
| globalPath | string | ❌ | `'./lang'` | Path for translation config files
|
|
339
|
-
| distPath | string | ✅ | `''` | Output path for built files
|
|
340
|
-
| distKey | string | ✅ | `'index'` | Main translation file name
|
|
341
|
-
| namespace | string | ✅ | `lang` | Project namespace for distinguishing translation configs
|
|
342
|
-
| originLang | string | ✅ | `'zh-cn'` | Source language
|
|
343
|
-
| targetLangList | string[] | ✅ | `['en']` | Target languages
|
|
344
|
-
| buildToDist | boolean | ❌ | `false` | Whether to bundle translation files into main build
|
|
345
|
-
| translator | Translator | ❌ | `GoogleTranslator` | Translator instance
|
|
346
|
-
| translatorOption | object | ❌ | `{}` | Translator options (lower priority than `translator`)
|
|
347
|
-
| rewriteConfig | boolean | ❌ | `true` | Whether to rewrite config file on each plugin run
|
|
348
|
-
| deepScan | boolean | ❌ | `false` | Experimental: Whether to perform deep string scanning
|
|
349
|
-
| commonTranslateKey | string | ❌ | `''` | General translation key
|
|
350
|
-
| insertFileExtensions | string[] | ❌ | `[]` | List of file extensions to insert translation code into
|
|
338
|
+
| Parameter | Type | Required | Default | Description |
|
|
339
|
+
| -------------------- | ---------- | -------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
340
|
+
| enabled | boolean | ❌ | `true` | Whether to trigger translation. |
|
|
341
|
+
| translateType | string | ❌ | `full-auto` | Translation mode: `full-auto` or `semi-auto` |
|
|
342
|
+
| translateKey | string | ✅ | `$t` | Translation function name (e.g., `$t`) |
|
|
343
|
+
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | Function calls to exclude from translation |
|
|
344
|
+
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | Patterns to exclude (e.g., file extensions) |
|
|
345
|
+
| excludedPath | string[] | ❌ | `['node_modules']` | Directories to exclude (e.g., `node_modules`) |
|
|
346
|
+
| includePath | RegExp[] | ❌ | `[/src\//]` | Whitelist of directories to include (default: `src`) |
|
|
347
|
+
| globalPath | string | ❌ | `'./lang'` | Path for translation config files |
|
|
348
|
+
| distPath | string | ✅ | `''` | Output path for built files |
|
|
349
|
+
| distKey | string | ✅ | `'index'` | Main translation file name |
|
|
350
|
+
| namespace | string | ✅ | `lang` | Project namespace for distinguishing translation configs |
|
|
351
|
+
| originLang | string | ✅ | `'zh-cn'` | Source language |
|
|
352
|
+
| targetLangList | string[] | ✅ | `['en']` | Target languages |
|
|
353
|
+
| buildToDist | boolean | ❌ | `false` | Whether to bundle translation files into main build |
|
|
354
|
+
| translator | Translator | ❌ | `GoogleTranslator` | Translator instance |
|
|
355
|
+
| translatorOption | object | ❌ | `{}` | Translator options (lower priority than `translator`) |
|
|
356
|
+
| rewriteConfig | boolean | ❌ | `true` | Whether to rewrite config file on each plugin run |
|
|
357
|
+
| deepScan | boolean | ❌ | `false` | Experimental: Whether to perform deep string scanning |
|
|
358
|
+
| commonTranslateKey | string | ❌ | `''` | General translation key |
|
|
359
|
+
| insertFileExtensions | string[] | ❌ | `[]` | List of file extensions to insert translation code into |
|
|
351
360
|
| isClear | boolean | ❌ | `false` | Whether to clear content not in context (clear source language key-value pairs not in context), only supported in build mode |
|
|
352
|
-
| isClearSpace
|
|
361
|
+
| isClearSpace | boolean | ❌ | `false` | Whether to remove whitespace from both ends of source strings, whitespace is preserved by default |
|
|
353
362
|
|
|
354
363
|
---
|
|
355
364
|
|
|
@@ -442,9 +451,9 @@ To update translations, simply modify `index.json`.
|
|
|
442
451
|
|
|
443
452
|
## 📦 User Group
|
|
444
453
|
|
|
445
|
-
|
|
454
|
+
QQ Group
|
|
446
455
|
|
|
447
|
-

|
|
448
457
|
|
|
449
458
|
---
|
|
450
459
|
|
|
@@ -472,6 +481,9 @@ Original authors: wenps, xu-code, Caleb-Xu, Winfans
|
|
|
472
481
|
|
|
473
482
|
## Changelog
|
|
474
483
|
|
|
484
|
+
### v1.1.9 (Recommended Version)
|
|
485
|
+
|
|
486
|
+
- Fixed issue where deepScan string splitting wasn't handling line breaks and other special characters
|
|
475
487
|
|
|
476
488
|
### v1.1.8 (Recommended Version)
|
|
477
489
|
|
|
@@ -500,7 +512,6 @@ Original authors: wenps, xu-code, Caleb-Xu, Winfans
|
|
|
500
512
|
- Added interval configuration for Google Translate
|
|
501
513
|
- Added support for custom interface parameters in translators
|
|
502
514
|
|
|
503
|
-
|
|
504
515
|
### v1.1.3 (Recommended Version)
|
|
505
516
|
|
|
506
517
|
- Added the ability to update languages without refreshing and best practices
|
package/readme.md
CHANGED
|
@@ -39,7 +39,7 @@ tips:有道翻译需要用户自己去申请有道的翻译服务,demo里面
|
|
|
39
39
|
|
|
40
40
|
---
|
|
41
41
|
|
|
42
|
-
## ❓ 常见问题
|
|
42
|
+
## ❓ 常见问题
|
|
43
43
|
|
|
44
44
|
[问题文档](https://juejin.cn/post/7483435518526062626)。
|
|
45
45
|
|
|
@@ -337,30 +337,30 @@ import '../lang/index.js' // 📍 必须在入口文件中第一行引入,文
|
|
|
337
337
|
|
|
338
338
|
## ⚙️ 配置参数说明
|
|
339
339
|
|
|
340
|
-
| 参数 | 类型 | 必选 | 默认值 | 描述
|
|
341
|
-
| -------------------- | ---------- | ---- | ------------------------ |
|
|
342
|
-
| enabled | boolean | ❌ | `true` | 是否触发翻译。
|
|
343
|
-
| translateType | string | ❌ | `full-auto` | 翻译状态,默认有两种可选`full-auto` 和 `semi-auto` 。
|
|
344
|
-
| translateKey | string | ✅ | `$t` | 翻译调用函数名称,例如`$t` 表示翻译调用时的函数名
|
|
345
|
-
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | 标记不会被翻译的函数调用列表
|
|
346
|
-
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | 用于标记排除不翻译的字符串模式,例如文件路径中的文件后缀
|
|
347
|
-
| excludedPath | string[] | ❌ | `['node_modules']` | 指定需要排除翻译的文件夹路径,例如默认会跳过`node_modules`
|
|
348
|
-
| includePath | RegExp[] | ❌ | `[/src\//]` | 指定只翻译某些目录路径(白名单),默认为`src`
|
|
349
|
-
| globalPath | string | ❌ | `'./lang'` | 翻译文件配置生成路径
|
|
350
|
-
| distPath | string | ✅ | `''` | 打包后生成的文件位置路径
|
|
351
|
-
| distKey | string | ✅ | `'index'` | 打包后生成的翻译主文件名称
|
|
352
|
-
| namespace | string | ✅ | `lang` | 项目命名空间,用于区分不同项目的翻译配置
|
|
353
|
-
| originLang | string | ✅ | `'zh-cn'` | 源语言,翻译以此语言为基础
|
|
354
|
-
| targetLangList | string[] | ✅ | `['en']` | 目标语言列表,支持配置多个语言
|
|
355
|
-
| buildToDist | boolean | ❌ | `false` | 是否在构建结束后将最新的翻译文件打包到主包中,默认不打包
|
|
356
|
-
| translator | Translator | ❌ | `GoogleTranslator` | 翻译器实例
|
|
357
|
-
| translatorOption | object | ❌ | `{}` | 翻译器的配置项,优先级低于`translator`
|
|
358
|
-
| rewriteConfig | boolean | ❌ | `true` | 插件每次运行时是否重写配置文件
|
|
359
|
-
| deepScan | boolean | ❌ | `false` | 实验性属性,表示是否进行深层扫描字符串
|
|
360
|
-
| commonTranslateKey | string | ❌ | `''` | 通用翻译key
|
|
361
|
-
| insertFileExtensions | string[] | ❌ | `[]` | 要插入翻译代码的文件扩展名列表
|
|
340
|
+
| 参数 | 类型 | 必选 | 默认值 | 描述 |
|
|
341
|
+
| -------------------- | ---------- | ---- | ------------------------ | ------------------------------------------------------------------------------------------- |
|
|
342
|
+
| enabled | boolean | ❌ | `true` | 是否触发翻译。 |
|
|
343
|
+
| translateType | string | ❌ | `full-auto` | 翻译状态,默认有两种可选`full-auto` 和 `semi-auto` 。 |
|
|
344
|
+
| translateKey | string | ✅ | `$t` | 翻译调用函数名称,例如`$t` 表示翻译调用时的函数名 |
|
|
345
|
+
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | 标记不会被翻译的函数调用列表 |
|
|
346
|
+
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | 用于标记排除不翻译的字符串模式,例如文件路径中的文件后缀 |
|
|
347
|
+
| excludedPath | string[] | ❌ | `['node_modules']` | 指定需要排除翻译的文件夹路径,例如默认会跳过`node_modules` |
|
|
348
|
+
| includePath | RegExp[] | ❌ | `[/src\//]` | 指定只翻译某些目录路径(白名单),默认为`src` |
|
|
349
|
+
| globalPath | string | ❌ | `'./lang'` | 翻译文件配置生成路径 |
|
|
350
|
+
| distPath | string | ✅ | `''` | 打包后生成的文件位置路径 |
|
|
351
|
+
| distKey | string | ✅ | `'index'` | 打包后生成的翻译主文件名称 |
|
|
352
|
+
| namespace | string | ✅ | `lang` | 项目命名空间,用于区分不同项目的翻译配置 |
|
|
353
|
+
| originLang | string | ✅ | `'zh-cn'` | 源语言,翻译以此语言为基础 |
|
|
354
|
+
| targetLangList | string[] | ✅ | `['en']` | 目标语言列表,支持配置多个语言 |
|
|
355
|
+
| buildToDist | boolean | ❌ | `false` | 是否在构建结束后将最新的翻译文件打包到主包中,默认不打包 |
|
|
356
|
+
| translator | Translator | ❌ | `GoogleTranslator` | 翻译器实例 |
|
|
357
|
+
| translatorOption | object | ❌ | `{}` | 翻译器的配置项,优先级低于`translator` |
|
|
358
|
+
| rewriteConfig | boolean | ❌ | `true` | 插件每次运行时是否重写配置文件 |
|
|
359
|
+
| deepScan | boolean | ❌ | `false` | 实验性属性,表示是否进行深层扫描字符串 |
|
|
360
|
+
| commonTranslateKey | string | ❌ | `''` | 通用翻译key |
|
|
361
|
+
| insertFileExtensions | string[] | ❌ | `[]` | 要插入翻译代码的文件扩展名列表 |
|
|
362
362
|
| isClear | boolean | ❌ | `false` | 是否清除已经不在上下文中的内容(清除项目中不再使用到的源语言键值对),仅仅支持打包模式下使用 |
|
|
363
|
-
| isClearSpace
|
|
363
|
+
| isClearSpace | boolean | ❌ | `false` | 是否清除源字符串中左右两边的空格,默认会保留空格 |
|
|
364
364
|
|
|
365
365
|
---
|
|
366
366
|
|
|
@@ -455,9 +455,9 @@ const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
|
455
455
|
|
|
456
456
|
## 📦 用户群
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
微信群已满,使用QQ群
|
|
459
459
|
|
|
460
|
-

|
|
461
461
|
|
|
462
462
|
---
|
|
463
463
|
|
|
@@ -485,6 +485,10 @@ const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
|
485
485
|
|
|
486
486
|
## 更新日志
|
|
487
487
|
|
|
488
|
+
### v1.1.9 (推荐版本)
|
|
489
|
+
|
|
490
|
+
- 修复 deepScan 切分字符串不处理换行符等问题
|
|
491
|
+
|
|
488
492
|
### v1.1.8 (推荐版本)
|
|
489
493
|
|
|
490
494
|
- 是否支持清除前后空格配置重命名
|
|
@@ -493,13 +497,13 @@ const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
|
493
497
|
|
|
494
498
|
- enable 能力兼容 翻译初始化补全
|
|
495
499
|
- 新增扫描是否支持清除前后空格配置
|
|
496
|
-
- 修复异常触发新增翻译问题
|
|
500
|
+
- 修复异常触发新增翻译问题
|
|
497
501
|
- 修复清理配置异常不生效问题
|
|
498
502
|
|
|
499
503
|
### v1.1.6 (推荐版本)
|
|
500
504
|
|
|
501
505
|
- 修复模板字符串前后空格清空导致 JSON 对应不上翻译函数的问题
|
|
502
|
-
- 修复插值中文括号导致插值失效的问题
|
|
506
|
+
- 修复插值中文括号导致插值失效的问题
|
|
503
507
|
- 新增清理配置功能
|
|
504
508
|
|
|
505
509
|
### v1.1.5 (推荐版本)
|