Skip to content

Commit

Permalink
l10n(zh-CN): New translations from Crowdin
Browse files Browse the repository at this point in the history
  • Loading branch information
hexo-crowdin[bot] committed Jul 4, 2024
1 parent aaf85ef commit 021063b
Show file tree
Hide file tree
Showing 45 changed files with 1,158 additions and 1,066 deletions.
39 changes: 21 additions & 18 deletions source/zh-cn/api/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,64 @@
title: Box
---

「Box」是 Hexo 用来处理特定文件夹中的文件的容器,在 Hexo 中有两个 Box,分别是 `hexo.source``hexo.theme`,前者用于处理 `source` 文件夹,而后者用于处理主题文件夹。
Box is a container used for processing files in a specified folder. 「Box」是 Hexo 用来处理特定文件夹中的文件的容器,在 Hexo 中有两个 Box,分别是 `hexo.source``hexo.theme`,前者用于处理 `source` 文件夹,而后者用于处理主题文件夹。 The former is used to process the `source` folder and the latter to process the `theme` folder.

## 加载文件

Box 提供了两种方法来加载文件:`process`, `watch`,前者用于加载文件夹内的所有文件;而后者除了执行 `process` 以外,还会继续监视文件变动。
Box 提供了两种方法来加载文件:`process`, `watch`,前者用于加载文件夹内的所有文件;而后者除了执行 `process` 以外,还会继续监视文件变动。 `process` loads all files in the folder. `watch` does the same, but also starts watching for file changes.

```js
box.process().then(function () {
// ...
box.process().then(function () {
// ...
});

box.watch().then(function () {
// 之后可调用 box.unwatch(),停止监视文件
});
});
```

## 比对路径

Box 提供了多种比对路径的模式,您可以以使用正则表达式(regular expression)、函数、或是 Express 风格的模式字符串,例如:
Box provides many ways for path matching. Box 提供了多种比对路径的模式,您可以以使用正则表达式(regular expression)、函数、或是 Express 风格的模式字符串,例如: For example:

```plain
posts/:id => posts/89
posts/*path => posts/2015/title
```

您可以以参考 [util.Pattern] 以获得更多信息。
您可以以参考 [util.Pattern][] 以获得更多信息。

## 处理器(Processor)

处理器(Processor)是 Box 中非常重要的元素,它用于处理文件,您可以使用上述的路径对比来限制该处理器所要处理的文件类型。使用 `addProcessor` 来添加处理器。
处理器(Processor)是 Box 中非常重要的元素,它用于处理文件,您可以使用上述的路径对比来限制该处理器所要处理的文件类型。 You can use path matching as described above to restrict what exactly the processor should process. 使用 `addProcessor` 来添加处理器。

```js
box.addProcessor("posts/:id", function (file) {
//
});
```

Box 在处理时会把目前处理的文件内容(`file`)传给处理器,您可以通过此参数获得该文件的数据。
Box passes the content of matched files to processors. This information can then be read straight from the `file` argument in the callback:

| 属性 | 描述 |
| -------- | --------------------------------------------------- |
| 属性 | 描述 |
| -------- | --------------------------------------------- |
| `source` | 文件完整路径 |
| `path` | 文件相对于 Box 的路径 |
| `type` | 文件类型。有 `create`, `update`, `skip`, `delete`|
| `params` | 从路径对比中取得的信息 |
| `path` | 文件相对于 Box 的路径 |
| `type` | 文件类型。 `create`, `update`, `skip`, `delete`|
| `params` | 从路径对比中取得的信息 |

Box 还提供了一些方法,让您无须手动处理文件 I/O。

| 方法 | 描述 |
| ------------ | ---------------- |
| `read` | 读取文件 |
| `readSync` | 同步读取文件 |
| `stat` | 读取文件状态 |
| 方法 | 描述 |
| ------------ | -------- |
| `read` | 读取文件 |
| `readSync` | 同步读取文件 |
| `stat` | 读取文件状态 |
| `statSync` | 同步读取文件状态 |
| `render` | 渲染文件 |
| `renderSync` | 同步渲染文件 |
| `render` | 渲染文件 |
| `renderSync` | 同步渲染文件 |

[util.Pattern]: https://github.com/hexojs/hexo-util#patternrule
21 changes: 11 additions & 10 deletions source/zh-cn/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
title: 控制台(Console)
---

控制台是 Hexo 与开发者之间沟通的桥梁。它注册并描述了可用的控制台命令。
控制台是 Hexo 与开发者之间沟通的桥梁。 它注册并描述了可用的控制台命令。

## 概要

```js
hexo.extend.console.register(name, desc, options, function (args) {
// ...
});
});
```

| 参数 | 描述 |
| --------- | ---- |
| Argument | 描述 |
| --------- | -- |
| `name` | 名称 |
| `desc` | 描述 |
| `options` | 选项 |

在函数中会传入 `args` 参数,此参数是使用者在终端中所传入的参数,是一个经 [Minimist] 解析的对象。
An argument `args` will be passed into the function. This is the argument that users type into the terminal. It's parsed by [Minimist][].

## 选项

### 用法

控制台的操作方法,例如:
The usage of a console command. For example:

```js
{
Expand All @@ -33,9 +34,9 @@ hexo.extend.console.register(name, desc, options, function (args) {
// hexo new [layout] <title>
```

### 参数
### arguments

控制台各个参数的说明,例如:
控制台各个参数的说明,例如: For example:

```js
{
Expand All @@ -46,17 +47,17 @@ hexo.extend.console.register(name, desc, options, function (args) {
}
```

### 选项
### options

控制台的各个选项的说明,例如:
控制台的各个选项的说明,例如: For example:

```js
{
options: [{ name: "-r, --replace", desc: "Replace existing files" }];
}
```

### 描述
### desc

关于控制台命令的更详细的信息。

Expand Down
3 changes: 2 additions & 1 deletion source/zh-cn/api/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ title: 部署器(Deployer)
hexo.extend.deployer.register(name, function (args) {
// ...
});
});
```

在函数中会传入 `args` 参数,该参数包含了 `_config.yml` 中的 `deploy` 参数值,以及开发者在终端中所传入的参数。
在函数中会传入 `args` 参数,该参数包含了 `_config.yml` 中的 `deploy` 参数值,以及开发者在终端中所传入的参数。 It contains the `deploy` value set in `_config.yml`, as well as the exact input users typed into their terminal.
22 changes: 11 additions & 11 deletions source/zh-cn/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@
title: 事件
---

Hexo 继承了 [EventEmitter],您可以用 `on` 方法监听 Hexo 所发布的事件,也可以使用 `emit` 方法对 Hexo 发布事件,更详细的说明请参阅 Node.js 的 API。
Hexo 继承了 [EventEmitter][],您可以用 `on` 方法监听 Hexo 所发布的事件,也可以使用 `emit` 方法对 Hexo 发布事件,更详细的说明请参阅 Node.js 的 API。 Use the `on` method to listen for events emitted by Hexo, and use the `emit` method to emit events. For more information, refer to the Node.js API documentation.

### deployBefore

在部署完成前发布。
Emitted before deployment begins.

### deployAfter

在部署成功后发布。
Emitted after deployment finishes.

### exit

在 Hexo 结束前发布。

### generateBefore

在静态文件生成前发布。
Emitted before generation begins.

### generateAfter

在静态文件生成后发布。
Emitted after generation finishes.

### new

在文章文件建立后发布。该事件返回文章参数。
在文章文件建立后发布。 该事件返回文章参数。

```js
hexo.on("new", function (post) {
//
});
```

| 数据 | 描述 |
| -------------- | ------------------ |
| 数据 | 描述 |
| -------------- | --------- |
| `post.path` | 文章文件的完整路径 |
| `post.content` | 文章文件的内容 |
| `post.content` | 文章文件的内容 |

### processBefore

在处理原始文件前发布。此事件会返回一个路径,代表 盒(Box)的根目录。
在处理原始文件前发布。 此事件会返回一个路径,代表 盒(Box)的根目录。

### processAfter

在原始文件处理后发布。此事件会返回一个路径,代表 盒(Box)的根目录。
在原始文件处理后发布。 此事件会返回一个路径,代表 盒(Box)的根目录。

### ready

Expand Down
47 changes: 34 additions & 13 deletions source/zh-cn/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 过滤器(Filter)
---

过滤器用于修改特定文件,Hexo 将这些文件依序传给过滤器,而过滤器可以针对文件进行修改,这个概念借鉴自 [WordPress](http://codex.wordpress.org/Plugin_API#Filters)
A filter is used to modify some specified data. Hexo passes data to filters in sequence and the filters then modify the data one after the other. This concept was borrowed from [WordPress](http://codex.wordpress.org/Plugin_API#Filters).

## 概要

Expand All @@ -16,10 +16,16 @@ hexo.extend.filter.register(type, function() {
const { config: themeCfg } = this.theme;
if (themeCfg.fancybox) // do something...

}, priority);

// Theme configuration
const { config: themeCfg } = this.theme;
if (themeCfg.fancybox) // do something...

}, priority);
```

您可以指定过滤器的优先级 `priority``priority` 值越低,过滤器会越早执行,默认的 `priority` 是 10。我们建议提供配置选项如 `hexo.config.your_plugin.priority`、让用户自行决定过滤器的优先级。
You can define the `priority`. Lower `priority` means that it will be executed first. 您可以指定过滤器的优先级 `priority``priority` 值越低,过滤器会越早执行,默认的 `priority` 是 10。 我们建议提供配置选项如 `hexo.config.your_plugin.priority`、让用户自行决定过滤器的优先级。

## 执行过滤器

Expand All @@ -28,12 +34,12 @@ hexo.extend.filter.exec(type, data, options);
hexo.extend.filter.execSync(type, data, options);
```

| 选项 | 描述 |
| --------- | ------------------ |
| `context` | Context |
| `args` | 参数。必须为数组。 |
| 选项 | 描述 |
| --------- | ---------- |
| `context` | Context |
| `args` | 参数。 必须为数组。 |

`data` 会作为第一个参数传入每个过滤器,而您可以在过滤器中通过返回值改变下一个过滤器中的 `data`,如果什么都没有返回的话则会保持原本的 `data`。您还可以使用 `args` 指定过滤器的其他参数。举例来说:
`data` 会作为第一个参数传入每个过滤器,而您可以在过滤器中通过返回值改变下一个过滤器中的 `data`,如果什么都没有返回的话则会保持原本的 `data` The `data` passed into the next filter can be modified by returning a new value. If nothing is returned, the data remains unmodified. 您还可以使用 `args` 指定过滤器的其他参数。 举例来说:

```js
hexo.extend.filter.register("test", function (data, arg1, arg2) {
Expand Down Expand Up @@ -94,7 +100,7 @@ hexo.extend.filter.unregister("example", require("path/to/filter"));

### before_post_render

在文章开始渲染前执行。您可以参考 [文章渲染](posts.html#渲染) 以了解执行顺序。
在文章开始渲染前执行。 您可以参考 [文章渲染](posts.html#渲染) 以了解执行顺序。

举例来说,把标题转为小写:

Expand All @@ -107,7 +113,7 @@ hexo.extend.filter.register("before_post_render", function (data) {

### after_post_render

在文章渲染完成后执行。您可以参考 [文章渲染](posts.html#渲染) 以了解执行顺序。
在文章渲染完成后执行。 您可以参考 [文章渲染](posts.html#渲染) 以了解执行顺序。

举例来说,把 `@username` 取代为 Twitter 的开发者链接。

Expand Down Expand Up @@ -139,16 +145,18 @@ hexo.extend.filter.register("before_exit", function () {
hexo.extend.filter.register("before_generate", function () {
// ...
});
});
```

### after_generate

在生成器解析后执行。
Executed after generation finishes.

```js
hexo.extend.filter.register("after_generate", function () {
// ...
});
});
```

### template_locals
Expand All @@ -172,6 +180,7 @@ hexo.extend.filter.register("template_locals", function (locals) {
hexo.extend.filter.register("after_init", function () {
// ...
});
});
```

### new_post_path
Expand All @@ -182,25 +191,37 @@ hexo.extend.filter.register("after_init", function () {
hexo.extend.filter.register("new_post_path", function (data, replace) {
// ...
});
});
```

### post_permalink

用来决定文章的永久链接。
Used to determine the permalink of posts.

```js
hexo.extend.filter.register("post_permalink", function (data) {
// ...
});
});
```

### after_render

在渲染后执行,您可以参考 [渲染](rendering.html#after-render-过滤器) 以了解更多信息。
Executed after rendering finishes. 在渲染后执行,您可以参考 [渲染](rendering.html#after-render-过滤器) 以了解更多信息。

### after_clean

Executed after generated files and cache are removed with `hexo clean` command.

```js
hexo.extend.filter.register("before_exit", function () {
// ...
});
```

### server_middleware

向服务器添加中间件(Middleware)。`app` 是一个 [Connect] 实例。
向服务器添加中间件(Middleware)。 `app` 是一个 [Connect][] 实例。

举例来说,在响应头中新增 `X-Powered-By: Hexo`

Expand Down
Loading

0 comments on commit 021063b

Please sign in to comment.