auto-i18n-plugin-core 1.1.16 → 1.1.17
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.d.ts +15 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +72 -72
- package/readme-en.md +78 -0
- package/readme.md +78 -0
- package/LICENSE +0 -9
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
2
|
+
"name": "auto-i18n-plugin-core",
|
|
3
|
+
"version": "1.1.17",
|
|
4
|
+
"description": "vite, webpack automatic translation plugin core code.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18n",
|
|
7
|
+
"auto i18n",
|
|
8
|
+
"vite i18n",
|
|
9
|
+
"webpack i18n",
|
|
10
|
+
"vue i18n",
|
|
11
|
+
"react i18n"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "rollup -c ./rollup.config.ts --configPlugin typescript"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git@github.com:wenps/auto-i18n-translation-plugins.git"
|
|
29
|
+
},
|
|
30
|
+
"author": "wenps,xu-code,Winfans,caleb-xu",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/wenps/auto-i18n-translation-plugins/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/wenps/auto-i18n-translation-plugins#readme",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@babel/core": "^7.23.2",
|
|
38
|
+
"@babel/generator": "^7.26.2",
|
|
39
|
+
"@babel/preset-env": "^7.23.2",
|
|
40
|
+
"@babel/preset-typescript": "^7.23.2",
|
|
41
|
+
"@babel/runtime": "^7.23.2",
|
|
42
|
+
"@vitalets/google-translate-api": "^9.2.0",
|
|
43
|
+
"axios": "^1.6.8",
|
|
44
|
+
"crypto-js": "^4.2.0",
|
|
45
|
+
"progress": "^2.0.3",
|
|
46
|
+
"tunnel": "0.0.6"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
50
|
+
"@babel/types": "^7.23.0",
|
|
51
|
+
"@rollup/plugin-alias": "^5.1.0",
|
|
52
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
53
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
54
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
55
|
+
"@types/babel__core": "^7.20.3",
|
|
56
|
+
"@types/babel__generator": "^7.6.8",
|
|
57
|
+
"@types/crypto-js": "^4.2.2",
|
|
58
|
+
"@types/node": "^20.3.3",
|
|
59
|
+
"@types/progress": "^2.0.7",
|
|
60
|
+
"@types/tunnel": "^0.0.7",
|
|
61
|
+
"babel-plugin-import": "^1.13.6",
|
|
62
|
+
"rollup": "^4.3.0",
|
|
63
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
64
|
+
"rollup-plugin-node-externals": "^7.1.2",
|
|
65
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
66
|
+
"typescript": "^5.1.6"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=14.18.0"
|
|
70
|
+
},
|
|
71
|
+
"volta": {
|
|
72
|
+
"extends": "../../package.json"
|
|
73
|
+
}
|
|
74
74
|
}
|
package/readme-en.md
CHANGED
|
@@ -358,6 +358,21 @@ Please import the language configuration file at the top of the **project entry
|
|
|
358
358
|
import '../lang/index.js' // 📍 Must be imported on the first line of the entry file. The file will be automatically generated when the plugin is run. By default, it is located in the 'lang' folder at the same level as the packaging configuration directory. The 'index.js' inside is the configuration file.
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
+
**Generated File Description:**
|
|
362
|
+
|
|
363
|
+
The generated `lang/index.js` file contains the following global functions and objects:
|
|
364
|
+
|
|
365
|
+
- `window.$t(key, defaultValue, namespace)` - Translation function
|
|
366
|
+
- `window.$$t(value)` - Simple translation function (returns original value)
|
|
367
|
+
- `window.$deepScan(value)` - Deep scan marker function (only effective when `deepScan: true`)
|
|
368
|
+
- `window.$iS(template, args)` - Interpolation string function (supports `${0}` or `\${0}` format placeholders)
|
|
369
|
+
- `window.$changeLang(lang)` - Language switching function
|
|
370
|
+
- `window.langMap` - Language mapping object
|
|
371
|
+
|
|
372
|
+
**Compatibility Guarantee:**
|
|
373
|
+
|
|
374
|
+
Starting from v1.1.17, all global functions and objects are mounted through an intelligent fallback mechanism, fully compatible with legacy browsers (including IE 11).
|
|
375
|
+
|
|
361
376
|
---
|
|
362
377
|
|
|
363
378
|
## ⚙️ Configuration Parameters
|
|
@@ -412,6 +427,59 @@ Since there's Chinese text, the whole string would be included, potentially caus
|
|
|
412
427
|
|
|
413
428
|
Now only '你好' gets translated, not the entire string.
|
|
414
429
|
|
|
430
|
+
### 🔥 Using the $deepScan Function
|
|
431
|
+
|
|
432
|
+
When `deepScan: true` is enabled, the plugin automatically generates a `$deepScan` global function. This function marks template strings that need deep scanning:
|
|
433
|
+
|
|
434
|
+
```js
|
|
435
|
+
// Wrap template strings with $deepScan
|
|
436
|
+
const template = $deepScan(`
|
|
437
|
+
<div class="container">
|
|
438
|
+
<h1>Welcome</h1>
|
|
439
|
+
<p>This is a test</p>
|
|
440
|
+
</div>
|
|
441
|
+
`)
|
|
442
|
+
|
|
443
|
+
// The plugin automatically converts it to:
|
|
444
|
+
const template = `
|
|
445
|
+
<div class="container">
|
|
446
|
+
<h1>${$t('Welcome')}</h1>
|
|
447
|
+
<p>${$t('This is a test')}</p>
|
|
448
|
+
</div>
|
|
449
|
+
`
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**Notes:**
|
|
453
|
+
- `$deepScan` only returns the original value at runtime without any processing
|
|
454
|
+
- Primarily used to tell the plugin at compile time that this string needs deep scanning
|
|
455
|
+
- Only takes effect when `deepScan: true` is configured
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## 🌐 Global Object Compatibility
|
|
460
|
+
|
|
461
|
+
Starting from v1.1.17, the generated translation config file (`lang/index.js`) is fully compatible with legacy browsers, including IE 11.
|
|
462
|
+
|
|
463
|
+
### Compatibility Mechanism
|
|
464
|
+
|
|
465
|
+
The plugin uses the following fallback priority to obtain the global object:
|
|
466
|
+
|
|
467
|
+
1. `globalThis` - Modern browsers (ES2020+)
|
|
468
|
+
2. `window` - Browser environment (IE 11+ compatible)
|
|
469
|
+
3. `global` - Node.js environment
|
|
470
|
+
4. `self` - Web Workers environment
|
|
471
|
+
|
|
472
|
+
### Supported Browser Versions
|
|
473
|
+
|
|
474
|
+
- ✅ Chrome 49+
|
|
475
|
+
- ✅ Firefox 52+
|
|
476
|
+
- ✅ Safari 10+
|
|
477
|
+
- ✅ Edge 12+
|
|
478
|
+
- ✅ IE 11
|
|
479
|
+
- ✅ All modern browsers
|
|
480
|
+
|
|
481
|
+
**No additional configuration needed** - the generated files automatically handle compatibility.
|
|
482
|
+
|
|
415
483
|
---
|
|
416
484
|
|
|
417
485
|
## 👋 `translateType` Functionality
|
|
@@ -515,6 +583,16 @@ Original authors: wenps, xu-code, Caleb-Xu, Winfans
|
|
|
515
583
|
|
|
516
584
|
## Changelog
|
|
517
585
|
|
|
586
|
+
### v1.1.17 (Latest Version)
|
|
587
|
+
|
|
588
|
+
- **Enhanced Global Object Compatibility**: Generated translation config files now support legacy browsers (IE 11+) through a fallback mechanism: `globalThis` → `window` → `global` → `self`
|
|
589
|
+
- **Optimized deepScan Feature**: Added `$deepScan` global function for marking template string parts that need deep scanning, improving translation accuracy
|
|
590
|
+
- **Improved Code Structure**: Optimized translation function generation logic, all code wrapped in IIFE to prevent global scope pollution
|
|
591
|
+
|
|
592
|
+
### v1.1.16 (Recommended Version)
|
|
593
|
+
|
|
594
|
+
- Fixed issue where double quotes in template strings caused abnormal ID mapping generation
|
|
595
|
+
|
|
518
596
|
### v1.1.15 (Recommended Version)
|
|
519
597
|
|
|
520
598
|
- Added Node 14 compatibility
|
package/readme.md
CHANGED
|
@@ -361,6 +361,21 @@ translator: new CustomTranslator()
|
|
|
361
361
|
import '../lang/index.js' // 📍 必须在入口文件中第一行引入,文件会在运行插件时自动生成,默认位于打包配置目录同层的lang文件夹中,其中的index.js就是配置文件
|
|
362
362
|
```
|
|
363
363
|
|
|
364
|
+
**生成的文件说明:**
|
|
365
|
+
|
|
366
|
+
生成的 `lang/index.js` 文件包含以下全局函数和对象:
|
|
367
|
+
|
|
368
|
+
- `window.$t(key, defaultValue, namespace)` - 翻译函数
|
|
369
|
+
- `window.$$t(value)` - 简单翻译函数(直接返回原值)
|
|
370
|
+
- `window.$deepScan(value)` - 深度扫描标记函数(仅在 `deepScan: true` 时有效)
|
|
371
|
+
- `window.$iS(template, args)` - 插值字符串函数(支持 `${0}` 或 `\${0}` 格式的占位符)
|
|
372
|
+
- `window.$changeLang(lang)` - 语言切换函数
|
|
373
|
+
- `window.langMap` - 语言映射对象
|
|
374
|
+
|
|
375
|
+
**兼容性保证:**
|
|
376
|
+
|
|
377
|
+
从 v1.1.17 开始,所有全局函数和对象都通过智能 fallback 机制挂载,完全兼容低版本浏览器(包括 IE 11)。
|
|
378
|
+
|
|
364
379
|
---
|
|
365
380
|
|
|
366
381
|
## ⚙️ 配置参数说明
|
|
@@ -414,6 +429,59 @@ import '../lang/index.js' // 📍 必须在入口文件中第一行引入,文
|
|
|
414
429
|
|
|
415
430
|
这样就只会翻译`你好`这个字符串,而不会翻译整个字符串。
|
|
416
431
|
|
|
432
|
+
### 🔥 $deepScan 函数的使用
|
|
433
|
+
|
|
434
|
+
在启用 `deepScan: true` 后,插件会自动生成 `$deepScan` 全局函数。此函数用于标记需要深度扫描的模板字符串:
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
// 使用 $deepScan 包裹模板字符串
|
|
438
|
+
const template = $deepScan(`
|
|
439
|
+
<div class="container">
|
|
440
|
+
<h1>欢迎使用</h1>
|
|
441
|
+
<p>这是一个测试</p>
|
|
442
|
+
</div>
|
|
443
|
+
`)
|
|
444
|
+
|
|
445
|
+
// 插件会自动转换为:
|
|
446
|
+
const template = `
|
|
447
|
+
<div class="container">
|
|
448
|
+
<h1>${$t('欢迎使用')}</h1>
|
|
449
|
+
<p>${$t('这是一个测试')}</p>
|
|
450
|
+
</div>
|
|
451
|
+
`
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**注意事项:**
|
|
455
|
+
- `$deepScan` 在运行时仅返回原始值,不做任何处理
|
|
456
|
+
- 主要用于在编译时告诉插件需要对该字符串进行深度扫描
|
|
457
|
+
- 只在 `deepScan: true` 配置下生效
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
## 🌐 全局对象兼容性说明
|
|
462
|
+
|
|
463
|
+
从 v1.1.17 版本开始,生成的翻译配置文件 (`lang/index.js`) 已经完全兼容低版本浏览器,包括 IE 11。
|
|
464
|
+
|
|
465
|
+
### 兼容性机制
|
|
466
|
+
|
|
467
|
+
插件使用以下 fallback 优先级获取全局对象:
|
|
468
|
+
|
|
469
|
+
1. `globalThis` - 现代浏览器(ES2020+)
|
|
470
|
+
2. `window` - 浏览器环境(兼容 IE 11+)
|
|
471
|
+
3. `global` - Node.js 环境
|
|
472
|
+
4. `self` - Web Workers 环境
|
|
473
|
+
|
|
474
|
+
### 支持的浏览器版本
|
|
475
|
+
|
|
476
|
+
- ✅ Chrome 49+
|
|
477
|
+
- ✅ Firefox 52+
|
|
478
|
+
- ✅ Safari 10+
|
|
479
|
+
- ✅ Edge 12+
|
|
480
|
+
- ✅ IE 11
|
|
481
|
+
- ✅ 所有现代浏览器
|
|
482
|
+
|
|
483
|
+
**无需额外配置**,生成的文件会自动处理兼容性问题。
|
|
484
|
+
|
|
417
485
|
---
|
|
418
486
|
|
|
419
487
|
## 👋 translateType 选项的作用
|
|
@@ -520,6 +588,16 @@ const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
|
520
588
|
|
|
521
589
|
## 更新日志
|
|
522
590
|
|
|
591
|
+
### v1.1.17 (最新版本)
|
|
592
|
+
|
|
593
|
+
- **新增全局对象兼容性增强**:生成的翻译配置文件现在支持低版本浏览器(IE 11+),通过 `globalThis` → `window` → `global` → `self` 的 fallback 机制确保兼容性
|
|
594
|
+
- **优化 deepScan 功能**:新增 `$deepScan` 全局函数,用于标记模板字符串中需要深度扫描的部分,提升翻译精准度
|
|
595
|
+
- **改进代码结构**:优化翻译函数生成逻辑,所有代码封装在 IIFE 中,避免全局作用域污染
|
|
596
|
+
|
|
597
|
+
### v1.1.16 (推荐版本)
|
|
598
|
+
|
|
599
|
+
- 修复模板字符串内部出现"导致生成id映射异常问题
|
|
600
|
+
|
|
523
601
|
### v1.1.15 (推荐版本)
|
|
524
602
|
|
|
525
603
|
- 补充node14兼容
|
package/LICENSE
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023-present
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|