Skip to content

Commit 1f8954e

Browse files
committed
Translate async-await
1 parent 9cb04e7 commit 1f8954e

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if you doesn't finish the translation in ten days.
172172

173173
- [ ] advanced_foreword (reserved)
174174
- [ ] appcontext
175-
- [ ] async-await [@rosekc](https://github.com/your_username) rosekc
175+
- [x] async-await [@rosekc](https://github.com/rosekc) rosekc
176176
- [ ] becomingbig
177177
- [ ] blueprints
178178
- [ ] changes

docs/locales/zh_CN/LC_MESSAGES/async-await.po

+47-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ msgstr ""
1010
"Report-Msgid-Bugs-To: \n"
1111
"POT-Creation-Date: 2021-05-25 19:31+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Last-Translator: rosekc <[email protected]>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
1515
"MIME-Version: 1.0\n"
1616
"Content-Type: text/plain; charset=utf-8\n"
@@ -19,7 +19,7 @@ msgstr ""
1919

2020
#: ../../async-await.rst:4
2121
msgid "Using ``async`` and ``await``"
22-
msgstr ""
22+
msgstr "使用 ``async`` 和 ``await``"
2323

2424
#: ../../async-await.rst:8
2525
msgid ""
@@ -28,21 +28,27 @@ msgid ""
2828
"``async`` extra (``pip install flask[async]``). This allows views to be "
2929
"defined with ``async def`` and use ``await``."
3030
msgstr ""
31+
"在安装 Flask 时使用 ``async`` 额外后缀(``pip install flask[async]``)后,"
32+
"包括路由、错误处理、请求前、请求后、清理(teardown)的函数都可以使用协程函数。"
33+
"这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。"
3134

3235
#: ../../async-await.rst:20
3336
msgid "Using ``async`` on Windows on Python 3.8"
34-
msgstr ""
37+
msgstr "在 Windows,Python 3.8 环境下使用 ``async``"
3538

3639
#: ../../async-await.rst:22
3740
msgid ""
3841
"Python 3.8 has a bug related to asyncio on Windows. If you encounter "
3942
"something like ``ValueError: set_wakeup_fd only works in main thread``, "
4043
"please upgrade to Python 3.9."
4144
msgstr ""
45+
"在 Windows,Python 3.8 环境下存在一个与 asyncio 相关的 bug。如果遇到"
46+
"类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息,"
47+
"请更新到 Python 3.9。"
4248

4349
#: ../../async-await.rst:28
4450
msgid "Performance"
45-
msgstr ""
51+
msgstr "性能"
4652

4753
#: ../../async-await.rst:30
4854
msgid ""
@@ -51,6 +57,9 @@ msgid ""
5157
" request comes in to an async view, Flask will start an event loop in a "
5258
"thread, run the view function there, then return the result."
5359
msgstr ""
60+
"异步函数需要一个事件循环来执行。作为一个 WSGI 应用,Flask 使用一个线程去处理"
61+
"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件"
62+
"循环,在这个事件循环中执行视图函数,然后返回结果。"
5463

5564
#: ../../async-await.rst:35
5665
msgid ""
@@ -60,6 +69,9 @@ msgid ""
6069
"etc. However, the number of requests your application can handle at one "
6170
"time will remain the same."
6271
msgstr ""
72+
"即使使用异步视图函数,每一个请求依然与一个线程绑定在一起。这样设计的好处是让"
73+
"视图函数中可以执行异步代码,例如多个并行的数据库查询,HTTP请求外部API等等。"
74+
"然而,同一时间应用本身能接受的请求数量不会改变。"
6375

6476
#: ../../async-await.rst:41
6577
msgid ""
@@ -69,10 +81,13 @@ msgid ""
6981
"most use cases, but Flask's async support enables writing and using code "
7082
"that wasn't possible natively before."
7183
msgstr ""
84+
"**异步并不一定比同步代码快。** 异步的优势是在IO密集任务上,但是在CPU密集任务上"
85+
"则不然。传统的 Flask 视图函数在大多数情况下是合适的选择,而 Flask 对异步的支持让"
86+
"运行和使用协程代码成为可能,这是以前原生环境无法做到的。"
7287

7388
#: ../../async-await.rst:49
7489
msgid "Background tasks"
75-
msgstr ""
90+
msgstr "后台任务"
7691

7792
#: ../../async-await.rst:51
7893
msgid ""
@@ -82,6 +97,9 @@ msgid ""
8297
"cancelled. Therefore you cannot spawn background tasks, for example via "
8398
"``asyncio.create_task``."
8499
msgstr ""
100+
"异步函数在其执行完成前,都一个事件循环中运行。当异步函数完成时,事件循环也将停止。"
101+
"这意味着异步函数完成的时候,所有尚未完成的其他衍生任务都将被取消。因此,不能使用"
102+
"类似 ``asyncio.create_task`` 的方法来创建后台任务。"
85103

86104
#: ../../async-await.rst:57
87105
msgid ""
@@ -92,10 +110,14 @@ msgid ""
92110
":ref:`asgi`. This works as the adapter creates an event loop that runs "
93111
"continually."
94112
msgstr ""
113+
"要使用后台任务,最好的方法就是使用任务队列去激活后台任务,而不是在视图函数中"
114+
"创建。考虑到这点,使用 ASGI 服务器来为 Flask 提供服务来创建后台任务,然后如"
115+
" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这种做法与适配器"
116+
"创建了一个持续运行的事件循环类似。"
95117

96118
#: ../../async-await.rst:66
97119
msgid "When to use Quart instead"
98-
msgstr ""
120+
msgstr "何时使用 Quart 作为替代品"
99121

100122
#: ../../async-await.rst:68
101123
msgid ""
@@ -106,6 +128,10 @@ msgid ""
106128
"handle many concurrent requests, long running requests, and websockets "
107129
"without requiring multiple worker processes or threads."
108130
msgstr ""
131+
"基于实现上的不同,Flask 的异步支持的性能比异步优先的框架会稍低。如果已经拥有"
132+
"一个以异步为主的代码库,考虑使用 `Quart`_ 是明智的选择。Quart 是一个基于 `ASGI`_ "
133+
"的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行"
134+
"的请求,以及 websockets 编程不再需要多个工作进程或线程。"
109135

110136
#: ../../async-await.rst:75
111137
msgid ""
@@ -116,10 +142,14 @@ msgid ""
116142
"whether you should use Flask, Quart, or something else is ultimately up "
117143
"to understanding the specific needs of your project."
118144
msgstr ""
145+
"当前已经可以使用 Gevent 或 Eventlet 运行 Flask 来得到使用异步请求处理的好处。"
146+
"这些库通过为底层 Python 库打补丁的方式实现,而 ``async``/``await`` 与 ASGI"
147+
"使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于"
148+
"了解项目的特定需求。"
119149

120150
#: ../../async-await.rst:87
121151
msgid "Extensions"
122-
msgstr ""
152+
msgstr "扩展"
123153

124154
#: ../../async-await.rst:89
125155
msgid ""
@@ -130,6 +160,10 @@ msgid ""
130160
"awaitable either and will probably be blocking if called within an async "
131161
"view."
132162
msgstr ""
163+
"Flask 扩展系统的实现先于 Flask 异步支持,所以并不会假设视图函数是异步的。如果扩展"
164+
"提供了对视图函数的有附加功能的装饰器,这些装饰器因为不会异步等待(await)函数运行或者不是"
165+
"异步可等待(awaitable)的,可能在异步视图函数上不能正常运行。扩展提供的其他函数或许"
166+
"同样不是异步可等待的,在异步视图函数调用的时候大概会阻塞。"
133167

134168
#: ../../async-await.rst:95
135169
msgid ""
@@ -138,21 +172,25 @@ msgid ""
138172
"provides a view function decorator add ``ensure_sync`` before calling the"
139173
" decorated function,"
140174
msgstr ""
175+
"扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。"
176+
"举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。"
141177

142178
#: ../../async-await.rst:110
143179
msgid ""
144180
"Check the changelog of the extension you want to use to see if they've "
145181
"implemented async support, or make a feature request or PR to them."
146182
msgstr ""
183+
"检查扩展的更新记录,查看是否实现了异步支持。如果没有可以向他们提交 PR。"
147184

148185
#: ../../async-await.rst:115
149186
msgid "Other event loops"
150-
msgstr ""
187+
msgstr "其他事件循环"
151188

152189
#: ../../async-await.rst:117
153190
msgid ""
154191
"At the moment Flask only supports :mod:`asyncio`. It's possible to "
155192
"override :meth:`flask.Flask.ensure_sync` to change how async functions "
156193
"are wrapped to use a different library."
157194
msgstr ""
158-
195+
"当前 Flask 只支持 :mod:`asyncio`。覆盖 :meth:`flask.Flask.ensure_sync` "
196+
"可以修改包裹异步函数的实现,以使用其他库。"

0 commit comments

Comments
 (0)