vite-auto-i18n-plugin 1.1.1 → 1.1.3
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/package.json +2 -2
- package/readme-en.md +482 -0
- package/readme.md +501 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-auto-i18n-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Vite automatic translation plugin compatible with Rollup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@babel/core": "^7.23.2",
|
|
34
34
|
"@babel/preset-env": "^7.23.2",
|
|
35
35
|
"@babel/preset-typescript": "^7.23.2",
|
|
36
|
-
"auto-i18n-plugin-core": "1.1.
|
|
36
|
+
"auto-i18n-plugin-core": "1.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@babel/types": "^7.23.0",
|
package/readme-en.md
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./logo.svg" alt="auto-i18n-translation-plugins" width="300">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# 🚀 auto-i18n-translation-plugins
|
|
6
|
+
|
|
7
|
+
## 🍉 Plugin Introduction
|
|
8
|
+
|
|
9
|
+
A 🎉 **frontend auto-translation plugin** that supports all JavaScript-based frontend frameworks (like Vue2/3 and React). No source code modification needed! Easily achieve multi-language support with one click 🌐🚀. Comes with Youdao and Google translation services by default, while supporting custom translators. Compatible with major build tools like Webpack, Vite, and Rollup.
|
|
10
|
+
|
|
11
|
+
### 🎯 Key Features:
|
|
12
|
+
|
|
13
|
+
- 🛠️ **No source code changes** - Quick multi-language translation with one click
|
|
14
|
+
- 🌐 **Supports multiple translation services** (Google, Youdao, and custom translators)
|
|
15
|
+
- 🔍 **Smart detection** of text needing translation
|
|
16
|
+
- 🔧 **Flexible configuration options** for different project needs
|
|
17
|
+
|
|
18
|
+
Note: Youdao translation requires users to apply for their translation service - the demo keys have been exhausted.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📚 Plugin Debugging
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm install
|
|
26
|
+
pnpm run build
|
|
27
|
+
pnpm run preview // Don't select React, contains too much English text
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📖 Supported Features
|
|
33
|
+
|
|
34
|
+
- **Frameworks**: All JavaScript-based frontend frameworks (Vue2/3, React, etc.)
|
|
35
|
+
- **Build Tools**: Fully compatible with Webpack, Vite, and Rollup 🚀
|
|
36
|
+
- **Translation Services**: Default support for **Youdao** and **Google** translation, plus custom translators
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🌟 Quick Start
|
|
41
|
+
|
|
42
|
+
### 1️⃣ Install Plugin
|
|
43
|
+
|
|
44
|
+
#### **Vite Projects:**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install vite-auto-i18n-plugin --save-dev
|
|
48
|
+
# or
|
|
49
|
+
yarn add vite-auto-i18n-plugin --dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### **Webpack Projects:**
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install webpack-auto-i18n-plugin --save-dev
|
|
56
|
+
# or
|
|
57
|
+
yarn add webpack-auto-i18n-plugin --dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 2️⃣ Basic Configuration
|
|
63
|
+
|
|
64
|
+
#### **Vite Configuration Example** (vite.config.js):
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import vitePluginsAutoI18n, { YoudaoTranslator } from 'vite-auto-i18n-plugin'
|
|
68
|
+
import vue from '@vitejs/plugin-vue'
|
|
69
|
+
import { defineConfig } from 'vite'
|
|
70
|
+
|
|
71
|
+
export default defineConfig({
|
|
72
|
+
plugins: [
|
|
73
|
+
vue({
|
|
74
|
+
template: {
|
|
75
|
+
compilerOptions: {
|
|
76
|
+
hoistStatic: false,
|
|
77
|
+
cacheHandlers: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
vitePluginAutoI18n({
|
|
82
|
+
translator: new YoudaoTranslator({
|
|
83
|
+
appId: '4cdb9baea8066fef',
|
|
84
|
+
appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### **Webpack Configuration Example** (webpack.config.js):
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
const webpackPluginsAutoI18n = require('webpack-auto-i18n-plugin')
|
|
95
|
+
const { YoudaoTranslator } = require('webpack-auto-i18n-plugin')
|
|
96
|
+
|
|
97
|
+
const i18nPlugin = new webpackPluginsAutoI18n.default({
|
|
98
|
+
translator: new YoudaoTranslator({
|
|
99
|
+
appId: '4cdb9baea8066fef',
|
|
100
|
+
appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
plugins: [
|
|
106
|
+
new VueLoaderPlugin(),
|
|
107
|
+
new HtmlWebpackPlugin({
|
|
108
|
+
template: './public/index.html'
|
|
109
|
+
}),
|
|
110
|
+
i18nPlugin
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### 3️⃣ Translator Configuration Examples
|
|
118
|
+
|
|
119
|
+
The plugin uses Google Translate by default (with a default proxy port of 7890). When your network does not support accessing Google, we recommend choosing **Youdao Translate** ✨, which offers excellent translation quality. Currently, the plugin has built - in translation functions for Google, Youdao, and Baidu. If you need a custom translator, you can refer to the examples below.
|
|
120
|
+
|
|
121
|
+
#### **Using Google Translate (default)**
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
import { GoogleTranslator } from 'vite-auto-i18n-plugin'
|
|
125
|
+
|
|
126
|
+
...
|
|
127
|
+
translator: new GoogleTranslator({
|
|
128
|
+
proxyOption: {
|
|
129
|
+
host: '127.0.0.1',
|
|
130
|
+
port: 7890,
|
|
131
|
+
headers: {
|
|
132
|
+
'User-Agent': 'Node'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
...
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### **Using Youdao Translate**
|
|
140
|
+
|
|
141
|
+
Requires API application: [API Docs](https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html)
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
import { YoudaoTranslator } from 'vite-auto-i18n-plugin'
|
|
145
|
+
|
|
146
|
+
...
|
|
147
|
+
translator: new YoudaoTranslator({
|
|
148
|
+
appId: 'your-app-id',
|
|
149
|
+
appKey: 'your-app-key'
|
|
150
|
+
})
|
|
151
|
+
...
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### **Baidu Translator**
|
|
155
|
+
|
|
156
|
+
Requires API application: [API Docs](https://api.fanyi.baidu.com/product/113)
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
import { BaiduTranslator } from 'vite-auto-i18n-plugin'
|
|
160
|
+
|
|
161
|
+
...
|
|
162
|
+
translator: new BaiduTranslator({
|
|
163
|
+
appId: 'your-app-id', // Baidu AppId
|
|
164
|
+
appKey: 'your-app-key' // Baidu AppKey
|
|
165
|
+
})
|
|
166
|
+
...
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### **Volcengine AI Translator**
|
|
170
|
+
|
|
171
|
+
Supports calling `doubao` or `deepseek` for translation. AI model translation provides more accurate results than traditional API translation, but takes longer to process.
|
|
172
|
+
Volcengine AI model introduction: https://www.volcengine.com/docs/82379/1099455.
|
|
173
|
+
Requires enabling the AI service and applying for API, [API documentation](https://www.volcengine.com/docs/82379/1298454).
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
import { VolcengineTranslator } from 'vite-auto-i18n-plugin'
|
|
177
|
+
|
|
178
|
+
...
|
|
179
|
+
translator: new VolcengineTranslator({
|
|
180
|
+
apiKey: 'your-api-key',
|
|
181
|
+
model: 'model-to-call, e.g. `doubao-1-5-pro-32k-250115`, please ensure the model has been enabled in console before using'
|
|
182
|
+
})
|
|
183
|
+
...
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
````
|
|
187
|
+
|
|
188
|
+
#### **Empty Translator**
|
|
189
|
+
|
|
190
|
+
If you only need to scan target language without translation, this translator will generate JSON files.
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
import { EmptyTranslator } from 'vite-auto-i18n-plugin'
|
|
194
|
+
|
|
195
|
+
...
|
|
196
|
+
translator: new EmptyTranslator()
|
|
197
|
+
...
|
|
198
|
+
````
|
|
199
|
+
|
|
200
|
+
#### **Custom Translator**
|
|
201
|
+
|
|
202
|
+
If you have your own translation API, you can create a custom translator:
|
|
203
|
+
|
|
204
|
+
Simplest way is using the base `Translator` class:
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
import { Translator } from 'vite-auto-i18n-plugin'
|
|
208
|
+
import axios from 'axios'
|
|
209
|
+
|
|
210
|
+
...
|
|
211
|
+
translator: new Translator({
|
|
212
|
+
name: 'My Translator',
|
|
213
|
+
// Translation method
|
|
214
|
+
fetchMethod: (str, fromKey, toKey, _separator) => {
|
|
215
|
+
// Actual API calls may be more complex than this example
|
|
216
|
+
const myApi = 'https://www.my-i18n.cn/api/translate?from=${fromKey}&to=${toKey}&t={+new Date}'
|
|
217
|
+
return axios.post(myApi, { str })
|
|
218
|
+
.then(res => res.data)
|
|
219
|
+
},
|
|
220
|
+
// API call interval (some APIs may block frequent requests)
|
|
221
|
+
interval: 1000
|
|
222
|
+
})
|
|
223
|
+
...
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
For advanced functionality, you can extend the class (though no current use cases):
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
import { Translator } from 'vite-auto-i18n-plugin'
|
|
230
|
+
|
|
231
|
+
class CustomTranslator extends Translator {
|
|
232
|
+
constructor () {
|
|
233
|
+
super({
|
|
234
|
+
name: 'My Translator',
|
|
235
|
+
...
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
...
|
|
241
|
+
translator: new CustomTranslator()
|
|
242
|
+
...
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
### 4️⃣ Project Entry Configuration 🏗️
|
|
248
|
+
|
|
249
|
+
Add this at the top of your **project entry file** (e.g., `main.js`):
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
import '../lang/index.js' // 📍 Must be imported first in entry file. This file is auto-generated when running the plugin, default location is lang folder at same level as build config directory
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## ⚙️ Configuration Parameters
|
|
258
|
+
|
|
259
|
+
| Parameter | Type | Required | Default | Description |
|
|
260
|
+
| -------------------- | ---------- | -------- | ------------------------ | -------------------------------------------------------- |
|
|
261
|
+
| enabled | boolean | ❌ | `true` | Whether to trigger translation. |
|
|
262
|
+
| translateType | string | ❌ | `full-auto` | Translation mode: `full-auto` or `semi-auto` |
|
|
263
|
+
| translateKey | string | ✅ | `$t` | Translation function name (e.g., `$t`) |
|
|
264
|
+
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | Function calls to exclude from translation |
|
|
265
|
+
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | Patterns to exclude (e.g., file extensions) |
|
|
266
|
+
| excludedPath | string[] | ❌ | `['node_modules']` | Directories to exclude (e.g., `node_modules`) |
|
|
267
|
+
| includePath | RegExp[] | ❌ | `[/src\//]` | Whitelist of directories to include (default: `src`) |
|
|
268
|
+
| globalPath | string | ❌ | `'./lang'` | Path for translation config files |
|
|
269
|
+
| distPath | string | ✅ | `''` | Output path for built files |
|
|
270
|
+
| distKey | string | ✅ | `'index'` | Main translation file name |
|
|
271
|
+
| namespace | string | ✅ | `lang` | Project namespace for distinguishing translation configs |
|
|
272
|
+
| originLang | string | ✅ | `'zh-cn'` | Source language |
|
|
273
|
+
| targetLangList | string[] | ✅ | `['en']` | Target languages |
|
|
274
|
+
| buildToDist | boolean | ❌ | `false` | Whether to bundle translation files into main build |
|
|
275
|
+
| translator | Translator | ❌ | `GoogleTranslator` | Translator instance |
|
|
276
|
+
| translatorOption | object | ❌ | `{}` | Translator options (lower priority than `translator`) |
|
|
277
|
+
| rewriteConfig | boolean | ❌ | `true` | Whether to rewrite config file on each plugin run |
|
|
278
|
+
| deepScan | boolean | ❌ | `false` | Experimental: Whether to perform deep string scanning |
|
|
279
|
+
| commonTranslateKey | string | ❌ | `''` | General translation key |
|
|
280
|
+
| insertFileExtensions | string[] | ❌ | `[]` | List of file extensions to insert translation code into |
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 🔍 What does `deepScan` do?
|
|
285
|
+
|
|
286
|
+
`deepScan` is an experimental property controlling whether the plugin performs deep string scanning.
|
|
287
|
+
|
|
288
|
+
By default, the plugin scans strings/template strings - if any target language text is found, the entire string is included:
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
;`<div>
|
|
292
|
+
<p>你好</p>
|
|
293
|
+
</div>`
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Since there's Chinese text, the whole string would be included, potentially causing inaccurate translation. With `deepScan` enabled, the plugin splits and reconstructs template strings, only translating matching text:
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
;`<div>
|
|
300
|
+
<p>${$t('你好')}</p>
|
|
301
|
+
</div>`
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Now only '你好' gets translated, not the entire string.
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## 👋 `translateType` Functionality
|
|
309
|
+
|
|
310
|
+
Added in v1.0.11, with two options:
|
|
311
|
+
|
|
312
|
+
`full-auto`: Fully automatic translation (default supports Chinese, Japanese, Korean, Russian)
|
|
313
|
+
|
|
314
|
+
`semi-auto`: Semi-automatic translation (supports all source languages)
|
|
315
|
+
|
|
316
|
+
In `semi-auto` mode, users must wrap target text with `translateKey` (e.g., `$t('hello')`), which the plugin will then translate.
|
|
317
|
+
|
|
318
|
+
Example:
|
|
319
|
+
|
|
320
|
+
```js
|
|
321
|
+
const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
322
|
+
return (
|
|
323
|
+
<div className="hello-world">
|
|
324
|
+
<h1>
|
|
325
|
+
{$t('Hello,')} {name}!
|
|
326
|
+
</h1>
|
|
327
|
+
<p>{$t('Welcome to our application')}</p>
|
|
328
|
+
</div>
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## ❓ Why `buildToDist`?
|
|
336
|
+
|
|
337
|
+
In Vite, the plugin only generates translation config files. Without `buildToDist`, these files won't be bundled. ⚠️ Enabling this bundles them but may create duplicate config files.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 🔄 How to Update Translations?
|
|
342
|
+
|
|
343
|
+
After running the plugin, two files are generated in `\lang`:
|
|
344
|
+
|
|
345
|
+
- **index.js**: Translation function logic
|
|
346
|
+
- **index.json**: Translation content
|
|
347
|
+
|
|
348
|
+
To update translations, simply modify `index.json`.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## ⚠️ Usage Notes
|
|
353
|
+
|
|
354
|
+
1. **Proxy Requirements**
|
|
355
|
+
|
|
356
|
+
- In China, **Youdao Translate** is strongly recommended
|
|
357
|
+
- Google Translate requires proxy configuration
|
|
358
|
+
- Default proxy port: **7890** (customizable via `proxyOption`)
|
|
359
|
+
|
|
360
|
+
2. **Translation Frequency**
|
|
361
|
+
|
|
362
|
+
- Google Translate is free but may limit frequent requests 🔒
|
|
363
|
+
- Set reasonable intervals between requests 💡
|
|
364
|
+
|
|
365
|
+
3. **Translation Updates**
|
|
366
|
+
- `index.json` in `globalPath` is the core translation file
|
|
367
|
+
- Changes take effect immediately after saving
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## 📦 User Group
|
|
372
|
+
|
|
373
|
+
WeChat Group
|
|
374
|
+
|
|
375
|
+

|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 📦 Example Project
|
|
380
|
+
|
|
381
|
+
Example project: [example](./example) (click to view)
|
|
382
|
+
|
|
383
|
+
## 📜 License
|
|
384
|
+
|
|
385
|
+
MIT License 🪪 - Free to use and contribute!
|
|
386
|
+
|
|
387
|
+
May this plugin make your i18n development easier and more efficient! 🌍✨
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## ✨ Update
|
|
392
|
+
|
|
393
|
+
Since v1.0.5, simply import the generated `index.js` in your entry file - no need to manually create language switching functions. 👏
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 🎆 Authors
|
|
398
|
+
|
|
399
|
+
Original authors: wenps, xu-code, Caleb-Xu, Winfans
|
|
400
|
+
|
|
401
|
+
## Changelog
|
|
402
|
+
|
|
403
|
+
### v1.1.1
|
|
404
|
+
|
|
405
|
+
- New translation disable function
|
|
406
|
+
|
|
407
|
+
### v1.1.0
|
|
408
|
+
|
|
409
|
+
- New AI translator
|
|
410
|
+
- New Vue2 extension plugin mechanism for translation plugins
|
|
411
|
+
|
|
412
|
+
### v1.0.26 (Recommended Version)
|
|
413
|
+
|
|
414
|
+
- Added custom extension arrays
|
|
415
|
+
|
|
416
|
+
### v1.0.25 (Recommended Version)
|
|
417
|
+
|
|
418
|
+
- Added a universal translation key
|
|
419
|
+
|
|
420
|
+
### v1.0.24 (Recommended Version)
|
|
421
|
+
|
|
422
|
+
- Fixed the exception issue in semi-automatic mode
|
|
423
|
+
|
|
424
|
+
### v1.0.23 (Recommended Version)
|
|
425
|
+
|
|
426
|
+
- Fixed a major bug in packaging and writing.
|
|
427
|
+
|
|
428
|
+
### v1.0.22
|
|
429
|
+
|
|
430
|
+
- Added scan translator
|
|
431
|
+
|
|
432
|
+
### v1.0.21
|
|
433
|
+
|
|
434
|
+
- Added deep scanning
|
|
435
|
+
|
|
436
|
+
### v1.0.20
|
|
437
|
+
|
|
438
|
+
- Fixed filter function issues and added config overwrite option
|
|
439
|
+
|
|
440
|
+
### v1.0.19
|
|
441
|
+
|
|
442
|
+
- Backward compatibility for config files
|
|
443
|
+
|
|
444
|
+
### v1.0.18
|
|
445
|
+
|
|
446
|
+
- Fixed optional chaining issues in older Node versions
|
|
447
|
+
|
|
448
|
+
### v1.0.17
|
|
449
|
+
|
|
450
|
+
- Basic SSR support (experimental)
|
|
451
|
+
|
|
452
|
+
### v1.0.16
|
|
453
|
+
|
|
454
|
+
- Fixed Vue3 comment node issues
|
|
455
|
+
|
|
456
|
+
### v1.0.15
|
|
457
|
+
|
|
458
|
+
- Added Baidu Translate
|
|
459
|
+
|
|
460
|
+
### v1.0.14
|
|
461
|
+
|
|
462
|
+
- Fixed new language type segmentation
|
|
463
|
+
- Added Japanese, Korean, Russian support
|
|
464
|
+
|
|
465
|
+
### v1.0.13
|
|
466
|
+
|
|
467
|
+
- Bug fixes
|
|
468
|
+
|
|
469
|
+
### v1.0.12
|
|
470
|
+
|
|
471
|
+
- Type optimizations
|
|
472
|
+
|
|
473
|
+
### v1.0.11
|
|
474
|
+
|
|
475
|
+
- Bug fixes
|
|
476
|
+
- Added `translateType` option for semi-auto mode
|
|
477
|
+
|
|
478
|
+
```js
|
|
479
|
+
// Users can wrap text with translateKey
|
|
480
|
+
// e.g., $t('hello') - plugin will scan and translate these
|
|
481
|
+
$t('hello')
|
|
482
|
+
```
|
package/readme.md
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./logo.svg" alt="auto-i18n-translation-plugins" width="300">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# 🚀 auto-i18n-translation-plugins
|
|
6
|
+
|
|
7
|
+
[English Documentation](./readme-en.md)
|
|
8
|
+
|
|
9
|
+
## 🍉 插件介绍
|
|
10
|
+
|
|
11
|
+
一个 🎉 **前端自动翻译插件**,支持所有编译成 JS 的前端框架(例如 Vue2/3 和 React)。无需修改源码,通过支持多种翻译服务,一键轻松实现多语言支持!🌐🚀 默认集成有道翻译和谷歌翻译,同时支持自定义翻译器,兼容 Webpack、Vite、Rollup 等主流构建工具。
|
|
12
|
+
|
|
13
|
+
### 🎯 核心优势:
|
|
14
|
+
|
|
15
|
+
- 🛠️ **无需改动源码**,一键快速翻译多语言;
|
|
16
|
+
- 🌐 **支持多种翻译服务**(包括 Google 和有道,及自定义翻译器);
|
|
17
|
+
- 🔍 **智能检测**需要翻译的文本;
|
|
18
|
+
- 🔧 提供 **灵活的配置选项**,满足不同项目需求。
|
|
19
|
+
|
|
20
|
+
tips:有道翻译需要用户自己去申请有道的翻译服务,demo里面的key已经被用完了。
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📚 插件调试
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm install
|
|
28
|
+
pnpm run build
|
|
29
|
+
pnpm run preview // 别选react,里面太多英文不好扫
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 📖 支持范围
|
|
35
|
+
|
|
36
|
+
- **框架**: 支持所有编译为 JS 的前端框架(如 Vue2/3 和 React 等)。
|
|
37
|
+
- **构建工具**: 完美兼容 Webpack、Vite 和 Rollup 🚀。
|
|
38
|
+
- **翻译服务**: 默认支持 **有道翻译** 和 **谷歌翻译**,并支持自定义翻译器。
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🌟 快速开始
|
|
43
|
+
|
|
44
|
+
### 切换语言
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
window.localStorage.setItem('lang', value)
|
|
48
|
+
window.location.reload()
|
|
49
|
+
|
|
50
|
+
// value 是 语言映射对象 的 key 值
|
|
51
|
+
// 映射对象默认存在于 lang/index.js 文件下
|
|
52
|
+
const langMap = {
|
|
53
|
+
'en': (),
|
|
54
|
+
'zhcn': ()
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 1️⃣ 安装插件
|
|
59
|
+
|
|
60
|
+
#### **Vite 项目:**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install vite-auto-i18n-plugin --save-dev
|
|
64
|
+
# 或
|
|
65
|
+
yarn add vite-auto-i18n-plugin --dev
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### **Webpack 项目:**
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install webpack-auto-i18n-plugin --save-dev
|
|
72
|
+
# 或
|
|
73
|
+
yarn add webpack-auto-i18n-plugin --dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 2️⃣ 基础配置
|
|
79
|
+
|
|
80
|
+
#### **Vite 配置示例** (vite.config.js):
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
import vitePluginsAutoI18n, { YoudaoTranslator } from 'vite-auto-i18n-plugin'
|
|
84
|
+
import vue from '@vitejs/plugin-vue'
|
|
85
|
+
import { defineConfig } from 'vite'
|
|
86
|
+
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
plugins: [
|
|
89
|
+
vue({
|
|
90
|
+
template: {
|
|
91
|
+
compilerOptions: {
|
|
92
|
+
hoistStatic: false,
|
|
93
|
+
cacheHandlers: false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
vitePluginsAutoI18n({
|
|
98
|
+
translator: new YoudaoTranslator({
|
|
99
|
+
appId: '4cdb9baea8066fef',
|
|
100
|
+
appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### **Webpack 配置示例** (webpack.config.js):
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
const webpackPluginsAutoI18n = require('webpack-auto-i18n-plugin')
|
|
111
|
+
const { YoudaoTranslator } = require('webpack-auto-i18n-plugin')
|
|
112
|
+
|
|
113
|
+
const i18nPlugin = new webpackPluginsAutoI18n.default({
|
|
114
|
+
translator: new YoudaoTranslator({
|
|
115
|
+
appId: '4cdb9baea8066fef',
|
|
116
|
+
appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
plugins: [
|
|
122
|
+
new VueLoaderPlugin(),
|
|
123
|
+
new HtmlWebpackPlugin({
|
|
124
|
+
template: './public/index.html'
|
|
125
|
+
}),
|
|
126
|
+
i18nPlugin
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 3️⃣ 翻译器配置示例
|
|
134
|
+
|
|
135
|
+
插件默认使用谷歌翻译(默认配置代理端口7890)。在网络不支持访问谷歌的情况下,我们建议优先选择 **有道翻译** ✨,翻译效果优秀。目前插件已经内置谷歌、有道和百度翻译功能。如果需要自定义翻译器,可参考下方的示例。
|
|
136
|
+
|
|
137
|
+
下方的示例以`vite`为例,`webpack`与其类似。
|
|
138
|
+
|
|
139
|
+
#### **使用谷歌翻译(默认)**
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
import { GoogleTranslator } from 'vite-auto-i18n-plugin'
|
|
143
|
+
|
|
144
|
+
...
|
|
145
|
+
translator: new GoogleTranslator({
|
|
146
|
+
proxyOption: {
|
|
147
|
+
host: '127.0.0.1',
|
|
148
|
+
port: 7890,
|
|
149
|
+
headers: {
|
|
150
|
+
'User-Agent': 'Node'
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
...
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### **使用有道翻译**
|
|
158
|
+
|
|
159
|
+
需要申请api,[api文档](https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html)。
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
import { YoudaoTranslator } from 'vite-auto-i18n-plugin'
|
|
163
|
+
|
|
164
|
+
...
|
|
165
|
+
translator: new YoudaoTranslator({
|
|
166
|
+
appId: '你申请的appId',
|
|
167
|
+
appKey: '你申请的appKey'
|
|
168
|
+
})
|
|
169
|
+
...
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### **百度翻译器**
|
|
173
|
+
|
|
174
|
+
需要申请api,[api文档](https://api.fanyi.baidu.com/product/113)。
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
import { BaiduTranslator } from 'vite-auto-i18n-plugin'
|
|
178
|
+
|
|
179
|
+
...
|
|
180
|
+
translator: new BaiduTranslator({
|
|
181
|
+
appId: '你申请的appId', // 百度翻译 AppId
|
|
182
|
+
appKey: '你申请的appKey' // 百度翻译 AppKey
|
|
183
|
+
})
|
|
184
|
+
...
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### **火山引擎ai翻译器**
|
|
188
|
+
|
|
189
|
+
支持调用`doubao`或`deepseek`进行翻译,ai大模型的翻译效果会比传统的api翻译更准确,但缺点在于耗时更长。
|
|
190
|
+
火山引擎大模型介绍:https://www.volcengine.com/docs/82379/1099455。
|
|
191
|
+
需要开通大模型服务并申请api,[api文档](https://www.volcengine.com/docs/82379/1298454)。
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
import { VolcengineTranslator } from 'vite-auto-i18n-plugin'
|
|
195
|
+
|
|
196
|
+
...
|
|
197
|
+
translator: new VolcengineTranslator({
|
|
198
|
+
apiKey: '你申请的apiKey',
|
|
199
|
+
model: '你要调用的模型,如:`doubao-1-5-pro-32k-250115`,请确保使用前已在控制台开通了对应模型'
|
|
200
|
+
})
|
|
201
|
+
...
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### **空翻译器**
|
|
205
|
+
|
|
206
|
+
如果只需要扫描目标语言,不翻译的话,该翻译器会生成json文件.
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
import { EmptyTranslator } from 'vite-auto-i18n-plugin'
|
|
210
|
+
|
|
211
|
+
...
|
|
212
|
+
translator: new EmptyTranslator()
|
|
213
|
+
...
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### **自定义翻译器**
|
|
217
|
+
|
|
218
|
+
如果你有一个自用的翻译接口,可以通过以下方式自定义翻译器——
|
|
219
|
+
|
|
220
|
+
最简单的就是直接用`Translator`基类定义翻译器实例。
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
import { Translator } from 'vite-auto-i18n-plugin'
|
|
224
|
+
import axios from 'axios'
|
|
225
|
+
|
|
226
|
+
...
|
|
227
|
+
translator: new Translator({
|
|
228
|
+
name: '我的翻译器',
|
|
229
|
+
// 翻译的方法
|
|
230
|
+
fetchMethod: (str, fromKey, toKey, _separator) => {
|
|
231
|
+
// 实际的接口调用可能比示例更复杂,具体可参考源码中YoudaoTranslator的实现,路径:packages\autoI18nPluginCore\src\translators\youdao.ts
|
|
232
|
+
const myApi = 'https://www.my-i18n.cn/api/translate?from=${fromKey}&to=${toKey}&t={+new Date}'
|
|
233
|
+
return axios.post(myApi, { str })
|
|
234
|
+
.then(res => res.data)
|
|
235
|
+
},
|
|
236
|
+
// 接口触发间隔,有些接口频繁触发会被拉黑,请根据实际情况设置一个合理的接口触发间隔
|
|
237
|
+
interval: 1000
|
|
238
|
+
})
|
|
239
|
+
...
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
如果要实现更高阶的功能,可以使用继承,不过目前还没有对应的场景。
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
import { Translator } from 'vite-auto-i18n-plugin'
|
|
246
|
+
|
|
247
|
+
class CustomTranslator extends Translator {
|
|
248
|
+
constructor () {
|
|
249
|
+
super({
|
|
250
|
+
name: '我的翻译器',
|
|
251
|
+
...
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
...
|
|
257
|
+
translator: new CustomTranslator()
|
|
258
|
+
...
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### 4️⃣ 项目入口配置 🏗️
|
|
264
|
+
|
|
265
|
+
请在 **项目入口文件**(如 `main.js`)的顶部引入语言配置文件:
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
import '../lang/index.js' // 📍 必须在入口文件中第一行引入,这个文件会在运行插件时自动生成,默认在打包配置目录的同一层的lang文件夹中,其中的index.js 就是配置文件了
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## ⚙️ 配置参数说明
|
|
274
|
+
|
|
275
|
+
| 参数 | 类型 | 必选 | 默认值 | 描述 |
|
|
276
|
+
| -------------------- | ---------- | ---- | ------------------------ | ---------------------------------------------------------- |
|
|
277
|
+
| enabled | boolean | ❌ | `true` | 是否触发翻译。 |
|
|
278
|
+
| translateType | string | ❌ | `full-auto` | 翻译状态,默认有两种可选`full-auto` 和 `semi-auto` 。 |
|
|
279
|
+
| translateKey | string | ✅ | `$t` | 翻译调用函数名称,例如`$t` 表示翻译调用时的函数名 |
|
|
280
|
+
| excludedCall | string[] | ❌ | `['$i8n', 'require', …]` | 标记不会被翻译的函数调用列表 |
|
|
281
|
+
| excludedPattern | RegExp[] | ❌ | `[/\.\w+$/]` | 用于标记排除不翻译的字符串模式,例如文件路径中的文件后缀 |
|
|
282
|
+
| excludedPath | string[] | ❌ | `['node_modules']` | 指定需要排除翻译的文件夹路径,例如默认会跳过`node_modules` |
|
|
283
|
+
| includePath | RegExp[] | ❌ | `[/src\//]` | 指定只翻译某些目录路径(白名单),默认为`src` |
|
|
284
|
+
| globalPath | string | ❌ | `'./lang'` | 翻译文件配置生成路径 |
|
|
285
|
+
| distPath | string | ✅ | `''` | 打包后生成的文件位置路径 |
|
|
286
|
+
| distKey | string | ✅ | `'index'` | 打包后生成的翻译主文件名称 |
|
|
287
|
+
| namespace | string | ✅ | `lang` | 项目命名空间,用于区分不同项目的翻译配置 |
|
|
288
|
+
| originLang | string | ✅ | `'zh-cn'` | 源语言,翻译以此语言为基础 |
|
|
289
|
+
| targetLangList | string[] | ✅ | `['en']` | 目标语言列表,支持配置多个语言 |
|
|
290
|
+
| buildToDist | boolean | ❌ | `false` | 是否在构建结束后将最新的翻译文件打包到主包中,默认不打包 |
|
|
291
|
+
| translator | Translator | ❌ | `GoogleTranslator` | 翻译器实例 |
|
|
292
|
+
| translatorOption | object | ❌ | `{}` | 翻译器的配置项,优先级低于`translator` |
|
|
293
|
+
| rewriteConfig | boolean | ❌ | `true` | 插件每次运行时是否重写配置文件 |
|
|
294
|
+
| deepScan | boolean | ❌ | `false` | 实验性属性,表示是否进行深层扫描字符串 |
|
|
295
|
+
| commonTranslateKey | string | ❌ | `''` | 通用翻译key |
|
|
296
|
+
| insertFileExtensions | string[] | ❌ | `[]` | 要插入翻译代码的文件扩展名列表 |
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## 🔍 deepScan 选项的作用?
|
|
301
|
+
|
|
302
|
+
`deepScan` 是一个实验性的属性,用于控制插件是否进行深层扫描字符串。
|
|
303
|
+
默认情况下,插件会扫描字符串或者模版字符串,只需要里面存在一个目标语言就会被扫进去,比如:
|
|
304
|
+
|
|
305
|
+
```js
|
|
306
|
+
;`<div>
|
|
307
|
+
<p>你好</p>
|
|
308
|
+
</div>`
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
因为里面有一个中文,所以整个字符串会被扫进去,可能会导致翻译不准确,因为我们只想翻译`你好`这个字符串,所以我们可以设置`deepScan`为`true`,插件会对字符串进行切割,重新拼接成模版字符串,值对符合的字符串进行翻译,比如:
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
;`<div>
|
|
315
|
+
<p>${$t('你好')}</p>
|
|
316
|
+
</div>`
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
这样就只会翻译`你好`这个字符串,而不会翻译整个字符串。
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## 👋 translateType 选项的作用
|
|
324
|
+
|
|
325
|
+
`translateType` 是 v1.0.11 新增的属性,有两个可选值`full-auto` 和 `semi-auto` 。
|
|
326
|
+
|
|
327
|
+
`full-auto` 第一个是全自动翻译,默认来源语言只支持`中日韩俄`四种语言。
|
|
328
|
+
|
|
329
|
+
`semi-auto` 第二个半自动翻译,支持所有来源语言。
|
|
330
|
+
|
|
331
|
+
使用 `semi-auto` 时,用户需要主动去使用`translateKey`对目标字符进行包裹,比如 \$t('hello'),插件会自动完成翻译。
|
|
332
|
+
|
|
333
|
+
例子:
|
|
334
|
+
|
|
335
|
+
```js
|
|
336
|
+
const HelloWorld: React.FC<HelloWorldProps> = ({ name = 'World' }) => {
|
|
337
|
+
return (
|
|
338
|
+
<div className="hello-world">
|
|
339
|
+
<h1>
|
|
340
|
+
{$t('Hello,')} {name}!
|
|
341
|
+
</h1>
|
|
342
|
+
<p>{$t('Welcome to our application')}</p>
|
|
343
|
+
</div>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## ❓ 为什么需要 `buildToDist`?
|
|
352
|
+
|
|
353
|
+
在 Vite 环境中,插件执行后仅会生成翻译配置文件。如果直接构建,虽然翻译配置文件已生成,但默认不会立即将之打包到主包中。⚠️ 因此提供了 `buildToDist` 选项,可在构建时主动将翻译文件打包到主包中。但需要注意,这可能导致您的项目中生成两份翻译配置文件。
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## 🔄 如何更新翻译?
|
|
358
|
+
|
|
359
|
+
完成插件运行后,`\lang` 目录会生成两个文件:`index.js` 和 `index.json`。
|
|
360
|
+
|
|
361
|
+
- **index.js**:存储翻译相关的函数逻辑。
|
|
362
|
+
- **index.json**:存储翻译文本内容。
|
|
363
|
+
|
|
364
|
+
如果需要更新翻译内容,可以直接修改 `index.json` 文件内容。
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## ⚠️ 使用注意事项
|
|
369
|
+
|
|
370
|
+
1. **代理要求**
|
|
371
|
+
|
|
372
|
+
- 国内使用,强烈推荐使用**有道翻译**
|
|
373
|
+
- 使用谷歌翻译的功能时,国内用户必须配置代理环境。
|
|
374
|
+
- 默认代理端口为 **7890**。
|
|
375
|
+
- 可通过 `proxyOption` 参数自定义代理端口。
|
|
376
|
+
|
|
377
|
+
2. **翻译频率**
|
|
378
|
+
|
|
379
|
+
- 谷歌翻译是免费服务,但频繁请求可能触发使用限制 🔒。
|
|
380
|
+
- 建议设置一个适当的时间间隔再发起新的翻译请求 💡。
|
|
381
|
+
|
|
382
|
+
3. **翻译更新机制**
|
|
383
|
+
|
|
384
|
+
- `globalPath` 目录中的 `index.json` 是核心翻译文件。
|
|
385
|
+
- 修改并保存后,您的翻译内容将立即更新。
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## 📦 用户群
|
|
390
|
+
|
|
391
|
+
微信群
|
|
392
|
+
|
|
393
|
+

|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 📦 示例项目
|
|
398
|
+
|
|
399
|
+
☁️ 示例项目参考仓库:[example](./example)(点击查看)
|
|
400
|
+
|
|
401
|
+
## 📜 许可证
|
|
402
|
+
|
|
403
|
+
本插件基于 **MIT License** 开源协议 🪪。自由使用,欢迎贡献!
|
|
404
|
+
|
|
405
|
+
希望它能让您的国际化开发变得更加简单和高效!🌍✨
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## ✨ 更新
|
|
410
|
+
|
|
411
|
+
自 1.0.5 版本起,用户只需在入口文件中引入插件生成文件夹下的 `index.js` 文件,无需再手动构建语言切换函数文件。👏
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
## 🎆 作者
|
|
416
|
+
|
|
417
|
+
原始作者:wenps、xu-code、Caleb-Xu、Winfans
|
|
418
|
+
|
|
419
|
+
## 更新日志
|
|
420
|
+
|
|
421
|
+
### v1.1.1
|
|
422
|
+
|
|
423
|
+
- 新增翻译禁用功能
|
|
424
|
+
|
|
425
|
+
### v1.1.0
|
|
426
|
+
|
|
427
|
+
- 新增ai翻译器
|
|
428
|
+
- 新增翻译插件vue2拓展插件机制
|
|
429
|
+
|
|
430
|
+
### v1.0.26 (推荐版本)
|
|
431
|
+
|
|
432
|
+
- 新增自定义拓展名数组
|
|
433
|
+
|
|
434
|
+
### v1.0.25 (推荐版本)
|
|
435
|
+
|
|
436
|
+
- 新增通用翻译key
|
|
437
|
+
|
|
438
|
+
### v1.0.24 (推荐版本)
|
|
439
|
+
|
|
440
|
+
- 修复半自动模式异常问题
|
|
441
|
+
|
|
442
|
+
### v1.0.23 (推荐版本)
|
|
443
|
+
|
|
444
|
+
- 修复打包写入重大bug
|
|
445
|
+
|
|
446
|
+
### v1.0.22
|
|
447
|
+
|
|
448
|
+
- 新增扫描翻译器
|
|
449
|
+
|
|
450
|
+
### v1.0.21
|
|
451
|
+
|
|
452
|
+
- 新增深度扫描
|
|
453
|
+
|
|
454
|
+
### v1.0.20
|
|
455
|
+
|
|
456
|
+
- 修复过滤函数异常问题,以及补充是否覆盖生成配置文件项
|
|
457
|
+
|
|
458
|
+
### v1.0.19
|
|
459
|
+
|
|
460
|
+
- 配置文件兼容旧版本
|
|
461
|
+
|
|
462
|
+
### v1.0.18
|
|
463
|
+
|
|
464
|
+
- 修复了低版本 Node 中可选链操作导致运行时异常的问题。
|
|
465
|
+
|
|
466
|
+
### v1.0.17
|
|
467
|
+
|
|
468
|
+
- 支持基本的服务器端渲染(实验性)
|
|
469
|
+
|
|
470
|
+
### v1.0.16
|
|
471
|
+
|
|
472
|
+
- 修复已知问题(vue3注释节点)
|
|
473
|
+
|
|
474
|
+
### v1.0.15
|
|
475
|
+
|
|
476
|
+
- 新增百度翻译
|
|
477
|
+
|
|
478
|
+
### v1.0.14
|
|
479
|
+
|
|
480
|
+
- 修复新增语言类型,不主动切割问题
|
|
481
|
+
- 自动翻译能力新增日语,韩语,俄语
|
|
482
|
+
|
|
483
|
+
### v1.0.13
|
|
484
|
+
|
|
485
|
+
- 已知问题修复
|
|
486
|
+
|
|
487
|
+
### v1.0.12
|
|
488
|
+
|
|
489
|
+
- 优化类型
|
|
490
|
+
|
|
491
|
+
### v1.0.11
|
|
492
|
+
|
|
493
|
+
- 修复已知缺陷
|
|
494
|
+
- 新增翻译状态选项,支持半自动状态
|
|
495
|
+
|
|
496
|
+
```js
|
|
497
|
+
// 用户可以用 translateKey 包裹需要翻译的文案
|
|
498
|
+
// 如:$t('hello'),插件会扫描这些文案并实现自动翻译
|
|
499
|
+
|
|
500
|
+
$t('hello')
|
|
501
|
+
```
|