Skip to content

Translate async-await #24

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

- [ ] advanced_foreword (reserved)
- [ ] appcontext [@rosekc](https://github.com/rosekc) rosekc
- [ ] async-await [@rosekc](https://github.com/your_username) rosekc
- [x] async-await [@rosekc](https://github.com/rosekc) rosekc
- [ ] becomingbig
- [x] blueprints [@frostming](https://github.com/frostming) Frost Ming
- [ ] changes
Expand Down
1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/advanced_foreword.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ msgid ""
"must build with caution, watching for exploits when building to your "
"requirements."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/api.po
Original file line number Diff line number Diff line change
Expand Up @@ -6613,4 +6613,3 @@ msgstr ""

#~ msgid "Raises"
#~ msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/appcontext.po
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,3 @@ msgid ""
"sent: :data:`appcontext_pushed`, :data:`appcontext_tearing_down`, and "
":data:`appcontext_popped`."
msgstr ""

57 changes: 48 additions & 9 deletions docs/locales/zh_CN/LC_MESSAGES/async-await.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-05-30 19:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Last-Translator: rosekc <[email protected]>\n"
"Language-Team: zh_CN <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
Expand All @@ -19,7 +19,7 @@ msgstr ""

#: ../../async-await.rst:4
msgid "Using ``async`` and ``await``"
msgstr ""
msgstr "使用 ``async`` 和 ``await``"

#: ../../async-await.rst:8
msgid ""
Expand All @@ -29,21 +29,28 @@ msgid ""
"where ``contextvars.ContextVar`` is available. This allows views to be "
"defined with ``async def`` and use ``await``."
msgstr ""
"只要在安装 Flask 时加上 ``async`` 额外依赖(``pip install flask[async]``),"
"包括路由、错误处理、请求前、请求后以及清理(teardown)的函数都可以使用协程函数。"
"这需要 Python 3.7+ 的环境,以提供 ``contextvars.ContextVar`` 的支持。"
"这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。"

#: ../../async-await.rst:21
msgid "Using ``async`` on Windows on Python 3.8"
msgstr ""
msgstr "在 Windows,Python 3.8 环境下使用 ``async``"

#: ../../async-await.rst:23
msgid ""
"Python 3.8 has a bug related to asyncio on Windows. If you encounter "
"something like ``ValueError: set_wakeup_fd only works in main thread``, "
"please upgrade to Python 3.9."
msgstr ""
"在 Windows,Python 3.8 环境下存在一个与 asyncio 相关的 bug。如果遇到"
"类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息,"
"请升级到 Python 3.9。"

#: ../../async-await.rst:29
msgid "Performance"
msgstr ""
msgstr "性能"

#: ../../async-await.rst:31
msgid ""
Expand All @@ -52,6 +59,9 @@ msgid ""
" request comes in to an async view, Flask will start an event loop in a "
"thread, run the view function there, then return the result."
msgstr ""
"异步函数需要一个事件循环来执行。作为一个 WSGI 应用,Flask 使用一个线程去处理"
Copy link
Collaborator

Choose a reason for hiding this comment

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

worker翻译为线程似不妥,建议翻为例程(worker)以总括进程线程协程,首次使用可附上原词,并参考翻译词汇的讨论结果

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已将 例程 放到 #12 投票中。

顺便一提有相关 worker 译为 例程 的例子吗?我是第一次见到这种翻译。

"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件"
"循环,在这个事件循环中执行视图函数,然后返回结果。"

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

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

#: ../../async-await.rst:50
msgid "Background tasks"
msgstr ""
msgstr "后台任务"

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

#: ../../async-await.rst:58
msgid ""
Expand All @@ -93,10 +112,14 @@ msgid ""
":ref:`asgi`. This works as the adapter creates an event loop that runs "
"continually."
msgstr ""
"要使用后台任务,最好的方法就是使用任务队列去激活后台任务,而不是在视图函数中"
"创建。考虑到这点,使用 ASGI 服务器来为 Flask 提供服务来创建后台任务,然后如"
" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这起作用是因为"
"适配器创建了一个持续运行的事件循环。"

#: ../../async-await.rst:67
msgid "When to use Quart instead"
msgstr ""
msgstr "何时使用 Quart 作为替代品"

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

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

#: ../../async-await.rst:88
msgid "Extensions"
msgstr ""
msgstr "扩展"

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

#: ../../async-await.rst:96
msgid ""
Expand All @@ -139,23 +174,28 @@ msgid ""
"provides a view function decorator add ``ensure_sync`` before calling the"
" decorated function,"
msgstr ""
"扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。"
"举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。"

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

#: ../../async-await.rst:116
msgid "Other event loops"
msgstr ""
msgstr "其他事件循环"

#: ../../async-await.rst:118
msgid ""
"At the moment Flask only supports :mod:`asyncio`. It's possible to "
"override :meth:`flask.Flask.ensure_sync` to change how async functions "
"are wrapped to use a different library."
msgstr ""
"当前 Flask 只支持 :mod:`asyncio`。通过覆写 :meth:`flask.Flask.ensure_sync` "
"来修改包裹异步函数的实现,以使用其他的库。"

#~ msgid ""
#~ "Routes, error handlers, before request, "
Expand All @@ -166,4 +206,3 @@ msgstr ""
#~ " allows views to be defined with "
#~ "``async def`` and use ``await``."
#~ msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/becomingbig.po
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,3 @@ msgid ""
"developers to improve the tools for larger applications is getting "
"feedback from users."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/blueprints.po
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,3 @@ msgstr ""
#: ../../blueprints.rst:302
msgid "See :doc:`/errorhandling`."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/changes.po
Original file line number Diff line number Diff line change
Expand Up @@ -2556,4 +2556,3 @@ msgstr ""
#: ../../../CHANGES.rst:1178
msgid "First public preview release."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/cli.po
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,3 @@ msgid ""
"PyCharm, we can copy that configuration and alter the *Script* argument "
"to run a different CLI command, e.g. ``flask shell``."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/config.po
Original file line number Diff line number Diff line change
Expand Up @@ -808,4 +808,3 @@ msgstr ""
#: ../../config.rst:760
msgid "Example usage for both::"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/contributing.po
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,3 @@ msgstr ""
#: ../../../CONTRIBUTING.rst:227
msgid "Read more about `Sphinx <https://www.sphinx-doc.org/en/stable/>`__."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/debugging.po
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ msgid ""
" can. If the reloader is not disabled, it could cause an unexpected "
"reload if code changes during debugging."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/asgi.po
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ msgid ""
"and then serving the ``asgi_app`` with the asgi server, e.g. using "
"`Hypercorn <https://gitlab.com/pgjones/hypercorn>`_,"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/cgi.po
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@ msgstr ""
#: ../../deploying/cgi.rst:59
msgid "For more information consult the documentation of your webserver."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/fastcgi.po
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,3 @@ msgstr ""
#: ../../deploying/fastcgi.rst:233
msgid "Different python interpreters being used."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ msgstr ""
#: ../../deploying/index.rst:25
msgid "Self-hosted options"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/mod_wsgi.po
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,3 @@ msgid ""
"This sets up the load paths according to the settings of the virtual "
"environment. Keep in mind that the path has to be absolute."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/deploying/uwsgi.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ msgid ""
"This configuration binds the application to ``/yourapplication``. If you"
" want to have it in the URL root its a bit simpler::"
msgstr ""

Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,3 @@ msgid ""
"If you want to rewrite the headers from another header, you might want to"
" use a fixer like this::"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/design.po
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,3 @@ msgid ""
"The idea of Flask is to build a good foundation for all applications. "
"Everything else is up to you or extensions."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/errorhandling.po
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,3 @@ msgid ""
"See :doc:`/debugging` for information about how to debug errors in "
"development and production."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/extensiondev.po
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,3 @@ msgid ""
"``python_requires=\">= 3.6\"`` in ``setup.py`` to indicate supported "
"versions."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/extensions.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ msgid ""
"create your own. Read :doc:`/extensiondev` to develop your own Flask "
"extension."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/foreword.po
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@ msgid ""
" curious about the Flask design principles, head over to the section "
"about :doc:`design`."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/htmlfaq.po
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,3 @@ msgstr ""
#: ../../htmlfaq.rst:206
msgid "For most applications, it is undoubtedly better to use HTML5 than XHTML."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/installation.po
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,3 @@ msgid ""
msgstr ""
"Flask 现在已经安装好了。阅读 :doc:`/quickstart` 或是前往 :doc:`文档概览 </index>` 进一步了解 "
"Flask。"

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/license.po
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,3 @@ msgid ""
"https://palletsprojects.com/p/flask/ if you use it in a medium that "
"supports links."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/logging.po
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,3 @@ msgid ""
":meth:`app.logger <flask.Flask.logger>` or its own named logger. Consult "
"each extension's documentation for details."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/appdispatch.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@ msgid ""
"falls back to another application if the creator function returns "
"``None``::"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/appfactories.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,3 @@ msgid ""
"Add in WSGI middlewares when the application is being created if "
"necessary."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/caching.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ msgid ""
"extension for Flask does. Flask-Caching supports various backends, and it"
" is even possible to develop your own caching backend."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/celery.po
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,3 @@ msgid ""
"Now that the worker is running, ``wait`` will return the result once the "
"task is finished."
msgstr ""

Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ msgid ""
" of the user in a cookie in a :meth:`~flask.Flask.before_request` "
"callback::"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/distribute.po
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,3 @@ msgid ""
"folder instead of copying the data over. You can then continue to work "
"on the code without having to run ``install`` again after each change."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/fabric.po
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,3 @@ msgid ""
" type ``fab deploy`` and see your application being deployed "
"automatically to one or more remote servers."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/favicon.po
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ msgid ""
"The `Favicon <https://en.wikipedia.org/wiki/Favicon>`_ article on "
"Wikipedia"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/fileuploads.po
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,3 @@ msgid ""
"called `Flask-Uploads`_ that implements a full fledged upload mechanism "
"that allows controlling which file extensions are allowed to be uploaded."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/flashing.po
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ msgid ""
" :func:`~flask.get_flashed_messages`. This is useful if you wish to "
"render each category in a separate block."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ msgid ""
"but Flask makes it easy to implement them. Some common patterns are "
"collected in the following pages."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/jquery.po
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,3 @@ msgid ""
"application demonstrating the code on this page, as well as the same "
"thing using ``XMLHttpRequest`` and ``fetch``."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/lazyloading.po
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ msgid ""
"to be in a file that is imported upfront to work properly on the first "
"request. The same goes for any kind of remaining decorator."
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/methodoverrides.po
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ msgstr ""
#: ../../patterns/methodoverrides.rst:37
msgid "To use this with Flask, wrap the app object with the middleware::"
msgstr ""

1 change: 0 additions & 1 deletion docs/locales/zh_CN/LC_MESSAGES/patterns/mongoengine.po
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ msgid ""
"Flask-MongoEngine adds helpful utilities on top of MongoEngine. Check out"
" their `documentation <Flask-MongoEngine_>`_ as well."
msgstr ""

Loading