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

🌐 Add Chinese translation for Tutorial - Middleware #2334

Merged
merged 8 commits into from
Mar 27, 2021

Conversation

lpdswing
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #2334 (b4820dd) into master (51e920e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2334   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          242       242           
  Lines         7396      7396           
=========================================
  Hits          7396      7396           

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 51e920e...b4820dd. Read the comment docs.

@lpdswing lpdswing closed this Nov 10, 2020
@lpdswing lpdswing reopened this Nov 10, 2020
@lpdswing
Copy link
Contributor Author

@tiangolo I don't know why occured this error when build doc .
image

@tiangolo
Copy link
Member

Hey @lpdswing ! Thanks for letting me know.

The error had nothing to do with you, it was caused by a recent change I made when I enabled the new features of Material for MkDocs Insiders, but I incorrectly handled the install in PRs from forks.

I just fixed it and updated your branch, so it's now passing and ready for review 🎉

@tiangolo tiangolo added awaiting-review lang-all Translations lang-zh Chinese translations labels Nov 10, 2020
@github-actions
Copy link
Contributor

@lpdswing
Copy link
Contributor Author

lpdswing commented Nov 11, 2020 via email

@lpdswing lpdswing mentioned this pull request Nov 11, 2020
docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved
docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved

* 它接收你的应用程序的每一个**request**.
* 然后它可以对这个**request**做一些事情或者执行任何需要的代码.
* 然后它将**request**传递给应用程序的其他部分 (通过某种*路径操作*).
Copy link
Contributor

Choose a reason for hiding this comment

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

然后它将请求传递给应用程序的其他部分(某个路径操作)进行处理。

docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved
* 然后它返回这个 **response**.

!!! note "技术细节"
如果你依赖了 `yield`, 退出代码将在执行中间件*后*执行.
Copy link
Contributor

Choose a reason for hiding this comment

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

如果你有使用了 yield 关键字的依赖,依赖中的退出代码将在执行中间件之后执行。

docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved
docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor


要创建中间件你可以在函数的顶部使用装饰器 `@app.middleware("http")`.

中间件参数接收:
Copy link
Contributor

Choose a reason for hiding this comment

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

中间件函数接收如下参数:

* 然后它返回这个 **响应**.

!!! note "技术细节"
如果你使用了 `yield`关键字依赖, 依赖中的退出代码将在执行中间件*后*执行.
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave a space after yield.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

删除空格?

Copy link
Contributor

Choose a reason for hiding this comment

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

应该是 yhield 前后都要有空格。

Copy link
Contributor

Choose a reason for hiding this comment

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

yield 后面加个空格


* `request`.
* 一个函数 `call_next` 它将接收 `request` 作为参数.
* 这个函数将 `request` 传递个相应的 *路径操作*.
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
Contributor Author

Choose a reason for hiding this comment

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

thx

!!! note "技术细节"
你也可以使用 `from starlette.requests import Request`.

**FastAPI** 为了开发者方便提供了该对象. 但其实它直接来自于Starlette.
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave a space before Starlette.

!!! tip
请记住可以 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">用'X-' 前缀</a>添加专有自定义请求头.

但是如果你想让浏览器中的客户端看到你的自定义请求头, 你需要把它们加到 CORS 配置 ([CORS (Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank}) 的 `expose_headers` 参数中,在 <a href="https://www.starlette.io/middleware/#corsmiddleware" class="external-link" target="_blank">Starlette's CORS docs</a>文档中.
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave spaces for Starlette's CORS docs.


### 在 `response` 的前和后

在任何*路径操作*收到`request`前,可以添加要和请求一起运行的代码.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap enlish words with a space.

@github-actions
Copy link
Contributor

Copy link
Contributor

@waynerv waynerv left a comment

Choose a reason for hiding this comment

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

You should also translate all the punctuation marks.

docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved
docs/zh/docs/tutorial/middleware.md Outdated Show resolved Hide resolved

要创建中间件你可以在函数的顶部使用装饰器 `@app.middleware("http")`.

中间件参数接收:
Copy link
Contributor

Choose a reason for hiding this comment

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

中间件函数接受:

* 然后它返回这个 **响应**.

!!! note "技术细节"
如果你使用了 `yield`关键字依赖, 依赖中的退出代码将在执行中间件*后*执行.
Copy link
Contributor

Choose a reason for hiding this comment

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

应该是 yhield 前后都要有空格。

@tiangolo tiangolo changed the title Add chinese translate for tutorial-middleware 🌐 Add Chinese translation for Tutorial - Middleware Nov 25, 2020
@tiangolo
Copy link
Member

Awesome! Thank you @lpdswing for your contribution! 🍰 🚀

And thanks @waynerv, @RunningIkkyu, and @maoyibo for the reviews 🙇 ☕


I'm going to wait for the punctuation fixes and then the approval by @waynerv before merging 🤓 📝

@github-actions
Copy link
Contributor

Copy link
Contributor

@waynerv waynerv left a comment

Choose a reason for hiding this comment

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

@tiangolo I think this PR is ready for merging.

@tiangolo
Copy link
Member

Excellent, thanks for the confirmation @waynerv ! 🚀

@tiangolo tiangolo merged commit 368d314 into fastapi:master Mar 27, 2021
0xMario27 added a commit to 0xMario27/fastapi that referenced this pull request Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved-2 lang-all Translations lang-zh Chinese translations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants