Koa中文文档(持续更新中)
发布于 6 年前 作者 92hackers 3121 次浏览 来自 分享

在搜索引擎里搜索“koa 中文”,你会看到许多koa中文文档。但是看来看去,都没有找到一份语句完全流畅、意思理解无误的译文版本。

****为此,Breword技术翻译小组对Koa的最新版本进行了翻译,并对照源码进行审校,确保最大程度上的理解无误。

点击这里查看Breword翻译的 Koa中文文档

与其他译文版本相比,我们采取了一些不同的翻译策略。以下仅列举几点加以说明,也欢迎大家在评论区进行讨论。

Application

  • app.proxy when true proxy header fields will be trusted.

其他版本的翻译:app.proxy 当真正的代理头字段将被信任时

Breword的翻译:app.proxy为true 时,代理的头部字段将会被解析。

这里trusted,我们没有直译成“被信任”,而是意译成“被解析”。

  • app.subdomainOffset offset of .subdomains to ignore [2]

其他版本的翻译:app.subdomainOffset 对于要忽略的 .subdomains 偏移[2]

Breword的翻译:app.subdomainOffset计算.subdomains时需要忽略的偏移量[2]

文档对subdomainOffset进行了举例说明。假设域名是"tobi.ferrets.example.com"。如果app.subdomainOffset没有设置,也就是说默认要忽略的偏移量是2,那么ctx.subdomains是[“ferrets”, “tobi”]。

  • app.context is the prototype from which ctx is created from. You may add additional properties to ctx by editing app.context. This is useful for adding properties or methods to ctx to be used across your entire app, which may be more performant (no middleware) and/or easier (fewer require()s) at the expense of relying more on ctx, which could be considered an anti-pattern.

其他版本的翻译:app.context 是从其创建 ctx 的原型。您可以通过编辑 app.context 为 ctx 添加其他属性。这对于将 ctx 添加到整个应用程序中使用的属性或方法非常有用,这可能会更加有效(不需要中间件)和/或 更简单(更少的 require()),而更多地依赖于ctx,这可以被认为是一种反模式。

Breword的翻译:app.context是ctx的原型。想要给ctx添加更多的属性,你可以修改app.context。这对在ctx上自定义一些能在app全局使用的属性和方法非常有用,而且性能高(不使用中间件)、更简单(更少使用require())。不足的地方在于过多依赖ctx,这可能被认为是反模式。

Context

  • overwrite a boolean indicating whether to overwrite previously set cookies of the same name (false by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.

其他版本的翻译:

overwrite 一个布尔值,表示是否覆盖以前设置的同名的 cookie (默认是 false). 如果是 true, 在同一个请求中设置相同名称的所有 Cookie(不管路径或域)是否在设置此Cookie 时从 Set-Cookie 标头中过滤掉。

Breword的翻译:

overwrite:布尔值,表示是否覆盖先前设置的同名cookie(默认是false)。如果设置为true,设置的cookie会覆盖同一请求里的同名cookie(无论路径或域名是否相同),即头部字段Set-Cookie会过滤掉之前设置的cookie。

Request

  • request.querystring: Get raw query string void of ?.

其他版本的翻译:根据 ? 获取原始查询字符串。

Breword的翻译:获取原始查询字符串,这个字符串不带有?(即?之后的查询字符串)。

void of的意思就是“不带有”。

  • request.search: Get raw query string with the ?.

其他版本的翻译: 使用 ? 获取原始查询字符串。

Breword的翻译:获取原始查询字符串,这个字符串带有?。

这里的“with”,意思不是“通过什么工具”,而是“带有”。源码里也对这个字段进行了说明。

Response

response.flushHeaders()

Flush any set headers, and begin the body.

其他版本的翻译:刷新任何设置的标头,并开始主体。

Breword的翻译:清空(Flush)任何已设置的头部字段,并开始把body发回到客户端。

为了更好地理解这个字段,我们查阅了node.js的官方文档关于request.flushHeaders()的说明

所以对应地来看response.flushHeaders(),意思就是服务器不用等待body,可以先发送头部字段到客户端,再发送body。

我们在github上建立了一个仓库,用于存放Breword翻译的开源文档。欢迎star。 Breword/awesome-sync-to-Chinese

1 回复

强力支持一波,翻译的很用心,已star

回到顶部