Skip to content

Commit a33a1a8

Browse files
committed
docs($cn): add plugin translation
1 parent ced6aac commit a33a1a8

File tree

2 files changed

+245
-151
lines changed

2 files changed

+245
-151
lines changed

packages/docs/docs/plugin/README.md

+90-41
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ sidebar: auto
44

55
# Plugins
66

7-
## Writing a Plugin
8-
97
Plugins usually add global-level functionality to VuePress. There is no strictly defined scope for a plugin - there are typically several types of plugins:
108

119
1. Extend the data generated at compile time. e.g. [@vuepress/plugin-last-updated](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-last-updated).
1210
2. Generate extra files before or after compilation. e.g. [@vuepress/plugin-pwa](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-pwa)
1311
3. Add extra pages. e.g. [@vuepress/plugin-i18n-ui](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-i18n-ui)
1412
4. Inject global UI. e.g. [@vuepress/plugin-back-to-top](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-back-to-top).
1513

16-
A plugin should export a `plain object`(`#1`). If the plugin needs to take options, it can be a function that exports a plain object(`#2`). The function will be called with the plugin's options as the first argument, along with [context](#plugin-context) which provides some compile-time metadata.
14+
## Writing a Plugin
15+
16+
A plugin should export a `plain JavaScript object`(`#1`). If the plugin needs to take options, it can be a function that exports a plain object(`#2`). The function will be called with the plugin's options as the first argument, along with [ctx](#ctx) which provides some compile-time metadata.
1717

1818
``` js
1919
// #1
@@ -32,7 +32,7 @@ module.exports = (options, ctx) => {
3232
```
3333

3434
::: tip
35-
A VuePress plugin module should leverage `CommonJS Module` because VuePress plugins runs on the Node side.
35+
A VuePress plugin module should be a `CommonJS Module` because VuePress plugins runs on the Node side.
3636
:::
3737

3838
## Using a plugin
@@ -49,7 +49,7 @@ module.exports = {
4949

5050
### Use plugins from a dependency
5151

52-
A plugin can be published on npm in `CommonJS` format as `vuepress-plugin-xxx`. then you can use it:
52+
A plugin can be published on npm in `CommonJS` format as `vuepress-plugin-xxx`. you can use it:
5353

5454
``` js
5555
module.exports = {
@@ -105,7 +105,7 @@ Plugins can have options specified by wrapping the name and an options object in
105105
module.exports = {
106106
plugins: [
107107
[
108-
require('./my-plugin.js'),
108+
'vuepress-plugin-xxx',
109109
{ /* options */ }
110110
]
111111
]
@@ -151,7 +151,57 @@ module.exports = {
151151

152152
:::
153153

154-
## Options
154+
## Life Cycle
155+
156+
### ready
157+
158+
- Type: `AsyncFunction`
159+
- Scope:`dev|build`
160+
161+
```js
162+
module.exports = {
163+
async ready() {
164+
// ...
165+
}
166+
}
167+
```
168+
169+
::: tip 提示
170+
171+
`ready` 钩子在应用初始化之后,并在某些特定的函数式 API 执行之前执行。这些函数式 API 包括:
172+
173+
- clientDynamicModules
174+
- enhanceAppFiles
175+
176+
:::
177+
178+
### updated
179+
180+
- Type: `Function`
181+
- Scope:`dev`
182+
183+
```js
184+
module.exports = {
185+
updated() {
186+
// ...
187+
}
188+
}
189+
```
190+
191+
### generated
192+
193+
- Type: `AsyncFunction`
194+
- Scope:`build`
195+
196+
```js
197+
module.exports = {
198+
async generated() {
199+
// ...
200+
}
201+
}
202+
```
203+
204+
## API
155205

156206
### name
157207

@@ -183,9 +233,8 @@ module.exports = {
183233

184234
A plugin can contain multiple plugins like a preset.
185235

186-
187236
```js
188-
// your plugin
237+
// A plugin
189238
module.exports = {
190239
plugins: [
191240
'tag',
@@ -237,7 +286,7 @@ Since VuePress is a Vue-SSR based application, there will be two webpack configu
237286
- Type: `Object|Function`
238287
- Default: undefined
239288

240-
Since using [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) via [chainWebpack](chainwebpack) would be a little complicated:
289+
Since using [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) via [chainWebpack](#chainwebpack) would be a little complicated:
241290

242291
```js
243292
module.exports = {
@@ -281,7 +330,7 @@ module.exports = (options, ctx) => ({
281330
- Type: `Object|Function`
282331
- Default: undefined
283332

284-
We can set aliases via [chainWebpack](chainwebpack):
333+
We can set aliases via [chainWebpack](#chainwebpack):
285334

286335
```js
287336
module.exports = (options, ctx) => ({
@@ -417,7 +466,7 @@ The file can `export default` a hook function which will work like `.vuepress/en
417466
It's worth mentioning that in order for plugin developers to be able to do more things at compile time, this option also supports dynamic code:
418467

419468
```js
420-
module.exports = (option, context) => {
469+
module.exports = (option, ctx) => {
421470
return {
422471
enhanceAppFiles: [{
423472
name: 'dynamic-code',
@@ -456,14 +505,14 @@ import { SOURCE_DIR } from '@dynamic/constans'
456505
- Type: `Function`
457506
- Default: `undefined`
458507

459-
A function used to extend or modify the [$page](../miscellaneous/global-computed.md#page) object. This function will be invoking once for each page at compile time
508+
A function used to extend or modify the [$page](../miscellaneous/global-computed.md#page) object. This function will be invoking once for each page at compile time.
460509

461510
```js
462511
module.exports = {
463512
extendPageData ($page) {
464513
const {
465514
_filePath, // file's absolute path
466-
_i18n, // access the client global mixins at build time, e.g _i18n.$localePath.
515+
_computed, // access the client global computed mixins at build time, e.g _computed.$localePath.
467516
_content, // file's raw content string
468517
_strippedContent, // file's content string without frontmatter
469518
key, // page's unique hash key
@@ -481,11 +530,11 @@ module.exports = {
481530
}
482531
```
483532

484-
::: warning Note
485-
These fields starting with an `_` means you can only access them during build time.
533+
::: warning 注意
534+
那些以 `_` 开头的字段意味着你只能在编译期访问。
486535
:::
487536

488-
e.g.
537+
例子:
489538

490539
``` js
491540
module.exports = {
@@ -495,17 +544,17 @@ module.exports = {
495544
}
496545
```
497546

498-
Then you can use this value via `this.$page.size` in any Vue component.
547+
然后你可以在任意的 Vue 中通过 `this.$page.size` 来访问这个变量。
499548

500549
### clientRootMixin
501550

502-
- Type: `String`
503-
- Default: `undefined`
551+
- 类型: `String`
552+
- 默认值: `undefined`
504553

505-
A path to the mixin file which allow you to control the life cycle of root component.
554+
指向 `mixin` 文件的路径,它让你你可以控制根组件的生命周期:
506555

507556
``` js
508-
// plugin's entry
557+
// 插件的入口
509558
const path = require('path')
510559

511560
module.exports = {
@@ -523,10 +572,10 @@ export default {
523572

524573
### additionalPages
525574

526-
- Type: `Array|Function`
527-
- Default: `undefined`
575+
- 类型: `Array|Function`
576+
- 默认值: `undefined`
528577

529-
Add a page pointing to a markdown file:
578+
增加一个指向某个 markdown 文件的页面:
530579

531580
```js
532581
const path = require('path')
@@ -541,7 +590,7 @@ module.exports = {
541590
}
542591
```
543592

544-
Add a page with explicit content:
593+
或增加一个具有明确内容的页面:
545594

546595
```js
547596
module.exports = {
@@ -561,7 +610,7 @@ module.exports = {
561610
}
562611
```
563612

564-
Add a pure route:
613+
或增加一个纯粹的路由:
565614

566615
```js
567616
module.exports = {
@@ -578,10 +627,10 @@ module.exports = {
578627

579628
### globalUIComponents
580629

581-
- Type: `Array|String`
582-
- Default: `undefined`
630+
- 类型: `Array|String`
631+
- 默认值: `undefined`
583632

584-
You might want to inject some global UI fixed somewhere on the page, e.g. `back-to-top`, `popup`. In VuePress, **a global UI is a Vue component**, you can define the component's name(s) in the plugin, e.g.
633+
你可以想注入某些全局的 UI,并固定在页面中的某处,如 `back-to-top`, `popup`。在 VuePress 中,**一个全局 UI 就是一个 Vue 组件。**你可以直接配置该全局组件的名称,如:
585634

586635
``` js
587636
module.exports = {
@@ -592,19 +641,19 @@ module.exports = {
592641
}
593642
```
594643

595-
Then, VuePress will automatically inject these components behind the theme container:
644+
VuePress 将会自动将这些组件注入到布局组件的隔壁:
596645

597646
```html
598647
<div id="app">
599-
<div class="theme-container"> ... </div>
648+
<div class="theme-container"> ... </div> <!-- Layout Component -->
600649
<div class="global-ui">
601650
<Component-1/>
602651
<Component-2/>
603652
</div>
604653
</div>
605654
```
606655

607-
## Context
656+
## ctx
608657

609658
Starting with VuePress 1.x.x, VuePress provides an `AppContext` object that stores all the state of the current app and can be accessed through the plugin API.
610659

@@ -613,48 +662,48 @@ Context of each plugin is a isolated context, they just inherit from the same ap
613662
:::
614663

615664
```js
616-
module.exports = (options, context) => {
665+
module.exports = (options, ctx) => {
617666
// ...
618667
}
619668
```
620669

621-
### context.isProd
670+
### ctx.isProd
622671

623672
- Type: `boolean`
624673

625674
Whether vuepress run in production environment mode.
626675

627-
### context.sourceDir
676+
### ctx.sourceDir
628677

629678
- Type: `string`
630679

631680
Root directory where the documents are located.
632681

633-
### context.tempPath
682+
### ctx.tempPath
634683

635684
- Type: `string`
636685

637686
Root directory where the temporary files are located.
638687

639-
### context.outDir
688+
### ctx.outDir
640689

641690
- Type: `string`
642691

643692
Output path.
644693

645-
### context.themePath
694+
### ctx.themePath
646695

647696
- Type: `string`
648697

649698
The path of the currently active theme.
650699

651-
### context.base
700+
### ctx.base
652701

653702
- Type: `string`
654703

655704
See: [base](../config/README.md#base).
656705

657-
### context.writeTemp
706+
### ctx.writeTemp
658707

659708
- Type: `Function`
660709

0 commit comments

Comments
 (0)