Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(core/view.md): translation #1577

Merged
merged 4 commits into from
Dec 13, 2017
Merged

Conversation

zhang-z
Copy link
Contributor

@zhang-z zhang-z commented Oct 28, 2017

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

Start to work on translation of core/view

@zhang-z zhang-z mentioned this pull request Oct 28, 2017
48 tasks
@codecov-io
Copy link

codecov-io commented Oct 28, 2017

Codecov Report

Merging #1577 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1577   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files          29       29           
  Lines         729      729           
=======================================
  Hits          726      726           
  Misses          3        3

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e05669...0ee6620. Read the comment docs.

@fengmk2 fengmk2 added the WIP label Nov 3, 2017
@atian25
Copy link
Member

atian25 commented Nov 29, 2017

hey, since we just update this docs for 2.x, so sorry for that, you need to checkout the newest zh_CN version and compare it.

@zhang-z
Copy link
Contributor Author

zhang-z commented Nov 29, 2017

@atian25 , thanks for the remind. I will checkout latest zh_CN version

@zhang-z
Copy link
Contributor Author

zhang-z commented Dec 6, 2017

@atian25 , the translation is done. You can go ahead to review.

In most cases, we need to fetch data, render with templates, then return to users.
So a view engine is essential.

[egg-view] is the built-in view solution of Egg.js.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

翻译里面少出现 Egg.js 吧,这句和下面那句可以改为类似: [egg-view] is a built-in plugin to standard multiple view engine usage. 这样的(要改改,语法啥的)


[egg-view] is the built-in view solution of Egg.js.
It allows more than one view engine to be used in one application.
All view engines are imported as plugins, and they provide the same rendering API interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结合上面那句,看看一起怎么说,这里的原意是,通过 egg-view 的规范化,应用开发者可以用同样的 API 来使用不同的模板引擎。

Due to the benefits of egg-view, developer could use the same API interface to work with different view engine, consistent experience 啥啥啥的... (同样语法要改改)

[egg-view] is the built-in view solution of Egg.js.
It allows more than one view engine to be used in one application.
All view engines are imported as plugins, and they provide the same rendering API interface.
To know more, see [View Plugin](../advanced/view-plugin.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see xxx for more detail.

@atian25 atian25 changed the title docs(core/view.md): start working on it, create PR docs(core/view.md): translation Dec 7, 2017
@atian25 atian25 requested a review from SunShinewyf December 7, 2017 01:44
@atian25 atian25 removed the WIP label Dec 7, 2017
To know more, see [View Plugin](../advanced/view-plugin.md).

Take the officially supported View plugin [egg-view-nunjucks] as example:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take...for example || take ...as an example

```

### Register plugin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable plugin会不会好一点


### root {String}

Root directory for template files. It's absolute path. Default value is `${baseDir}/app/view`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个觉得不用断句了,直接 Root directory for template files is an absolute path

Multiple directories, separated by `,`, are supported.
[egg-view] looks for template files from all the directories.

Below is an example of configuring multiple `view` directories:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

below是一个副词,建议这样用 the configuration below is an example of multiple view directories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the configuration below"肯定是更书面更稳妥的表达,已按此提交修改。但其实"the above is", "the following is"都是常见用法: https://english.stackexchange.com/questions/172709/the-above-is-correct-the-below-is-not

Cache template file paths, default value is `true`.
[egg-view] looks for template files from the directories that defined in `root`.
If a matching is found, the file path will be cached.
The next time the same path is used,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉连成整句会好一点:the file path matched will be cached and be reused while rendering the same path next time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改成整句。不过我又把它写的冗长了点When a file matching given template path is found, the full file path will be cached and be reused when rendering the same template path afterward。因为我觉得"template path"和"full file path"值得区分一下,后者是包含了view root directory的绝对路径,因此才有cache的意义。如果是把"home.nj"本身cache起来,显然莫名其妙

[egg-view] provides three interfaces in Context.
All three returns a Promise:

- `render(name, locals)` renders template file, and set to value to `ctx.body`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set to -> set


- `app.locals` is global, usually configured in `app.js`.
- `ctx.locals` is per-request, and it merges `app.locals`.
- set `ctx.locals` with a new object, [egg-view] auto merges the new object into the previous object using setter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新的中文文档是:可以直接赋值对象,框架在对应的 setter 里面会自动 merge。下面这样翻译是不是好一点:
The object can be assigned directly, and[egg-view] will automatically merge in the corresponding setter

console.log(ctx.locals); // { a: 1, b: 2, c: 3, d: 4 }
```

In real development, we usually don't directly use these two objects in controller.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real感觉不太好,directly放在句尾好一点

Instead, simply call `ctx.render(name, data)`:
- [egg-view] auto merges `data` into `ctx.locals`.
- [egg-view] auto injects `ctx`, `request`, `helper` into locals for your convenience.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 auto 改为 automatically 会不会好一点,然后放在句尾


## Security

The built-in plugin [egg-security] provides common security related functions, including `helper.shtml / surl / sjs` and so on. You're strongly recommended to read [Security](./security.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're strongly recommended to read 被字句改为下面的句型:
It is strongly recommended to read [Security]

@zhang-z
Copy link
Contributor Author

zhang-z commented Dec 11, 2017

@atian25 , @SunShinewyf , 谢谢两位的审阅。之前完全是根据中文文档直译的,几处过于生硬。除了你们的意见,我也补充了个别修改,主要是我自己在读中文文档时就觉得描述不够准确的地方。详见da22e29

@atian25
Copy link
Member

atian25 commented Dec 11, 2017

@zhang-z rebase 下 push -f

@zhang-z zhang-z force-pushed the feature/docs-core-view branch from da22e29 to ccb72c9 Compare December 11, 2017 14:25
@zhang-z
Copy link
Contributor Author

zhang-z commented Dec 11, 2017

@atian25 , rebase done


In most cases, we need to fetch data, render with templates, then return to users.
So a view engine is essential.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议改为:we need to fetch data and render the templates
最新的中文文档是:故我们需要引入对应的模板引擎。所以感觉下一句最好为:So we need to use corresponding view template

In most cases, we need to fetch data, render with templates, then return to users.
So a view engine is essential.

[egg-view] is a built-in plugin to standardize the way of using view engines.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize-> support,view engines -> multiple view engines,感觉上面的翻译和文档不太相符

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句和下面一句都是按atian的修改意见稍加改动。#1577 (review)
我觉得两者都可以。你看用哪个?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是中文文档是这样的:框架内置 egg-view 作为模板解决方案,并支持多模板渲染,你的翻译里面没有“支持多模板渲染“,加上就ok了

So a view engine is essential.

[egg-view] is a built-in plugin to standardize the way of using view engines.
With [egg-view] developers can use the same API interface to work with different view engines in one application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新中文是:每个模板引擎都以插件的方式引入,但保持渲染的 API 一致。
感觉翻译得有点漏,比如“以插件的方式引入好像没有翻译到”
建议:each view engine is introduced with a way like the plugin but uses the same rendered API

Copy link
Contributor Author

@zhang-z zhang-z Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句也是按atian的回复略作修改。我原句是"All view engines are imported as plugins",我觉得会比"a way like the plugin"更好的点,因为模板引擎“是”插件,而不只是“像”插件。你再看看采用哪个表达?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉as会好一点


### root {String}

Root directory for template files is absolute path. Default value is `${baseDir}/app/view`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value和前面是连起来的,建议改成:Root directory for template files is absolute path,
it's default value is

Root directory for template files is absolute path. Default value is `${baseDir}/app/view`.
Multiple directories, separated by `,`, are supported.
[egg-view] looks for template files from all the directories.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一句读起来怪怪的:建议[egg-view] supports configuring multiple directories,which are separated by , , in this way, it will look for template files from all the directories. 这种,不过可以精简一下


## Security

The built-in plugin [egg-security] provides common security related functions, including `helper.shtml / surl / sjs` and so on. It's strongly recommended to read [Security](./security.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的辅助(related)翻译成helper是不是会好一点

Instead, simply call `ctx.render(name, data)`:
- [egg-view] merges `data` into `ctx.locals` automatically.
- [egg-view] injects `ctx`, `request`, `helper` into locals automatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉这里的框架不是指egg-view,而是指egg呢

Copy link
Contributor Author

@zhang-z zhang-z Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个确实是egg-view做的, 因为对中文文档的“框架”有疑惑,我翻的时候还特意查过源代码:https://github.com/eggjs/egg-view/blob/master/lib/context_view.js#L103

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额,那就是我理解错了,忽略

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都行的,因为 egg-view 是内置到 egg 里面的

## Locals

In the process of rendering pages,
we usually need a variable to hold all information that is used in view template.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的hold改为contain感觉会好一点


Cache template file paths, default value is `true`.
[egg-view] looks for template files from the directories that defined in `root`.
When a file matching given template path is found, the full file path will be cached
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a file matching given template path is found,这一句读起来好怪异
the framework will search according to the directories configured by root and won't search the same path which is matched next time
有点长,可以拆解一下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"No files matching path ..." 是挺常见的系统报错吧。你说的怪异是指?

@zhang-z zhang-z force-pushed the feature/docs-core-view branch from ccb72c9 to 0ee6620 Compare December 12, 2017 11:42
@zhang-z
Copy link
Contributor Author

zhang-z commented Dec 12, 2017

@SunShinewyf , 已更新。详见0ee6620

@SunShinewyf
Copy link
Contributor

@atian25 ok了,可以merge了

@atian25 atian25 merged commit 18f93f0 into eggjs:master Dec 13, 2017
@atian25
Copy link
Member

atian25 commented Dec 13, 2017

thanks a lot, @zhang-z @SunShinewyf

popomore pushed a commit that referenced this pull request Dec 13, 2017
docs(core/view.md): translation (#1577)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants