From d19f0eee81c7cfbe199cabfd573b1caafee19467 Mon Sep 17 00:00:00 2001 From: husohome Date: Sun, 13 Jul 2025 00:38:17 +0800 Subject: [PATCH 01/10] translate library/contextvars.po --- library/contextvars.po | 182 +++++++++++++++++++++++++++++++++++------ 1 file changed, 155 insertions(+), 27 deletions(-) diff --git a/library/contextvars.po b/library/contextvars.po index b229a722fe..b103866cdf 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -5,7 +5,7 @@ msgstr "" "Project-Id-Version: Python 3.13\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-10-31 00:13+0000\n" -"PO-Revision-Date: 2018-07-15 18:56+0800\n" +"PO-Revision-Date: 2025-07-13 00:28+0800\n" "Last-Translator: \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -13,6 +13,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 3.6\n" #: ../../library/contextvars.rst:2 msgid ":mod:`!contextvars` --- Context Variables" @@ -26,6 +27,9 @@ msgid "" "the :class:`~contextvars.Context` class should be used to manage the current " "context in asynchronous frameworks." msgstr "" +"本模組供 API 來管理、儲存及存取 context-local 狀態。 用 :class:`~contextvars." +"ContextVar` 型別宣告和處理 *情境變數*。 :func:`~contextvars.copy_context` 函式" +"和 :class:`~contextvars.Context` 類別來在非同步框架中管理目前的情境。" #: ../../library/contextvars.rst:17 msgid "" @@ -33,18 +37,21 @@ msgid "" "func:`threading.local` to prevent their state from bleeding to other code " "unexpectedly, when used in concurrent code." msgstr "" +"帶有狀態的 Context Manager 應該使用情境變數,不要用 :func:`threading.local`," +"才能防止它們的狀態在並行(concurrent)程式碼中使用時意外外溢並干擾到其他程式" +"碼。" #: ../../library/contextvars.rst:21 msgid "See also :pep:`567` for additional details." -msgstr "額外資訊請見 :pep:`567`。" +msgstr "其他詳細資訊,請參閱 :pep:`567`。" #: ../../library/contextvars.rst:27 msgid "Context Variables" -msgstr "" +msgstr "情境變數" #: ../../library/contextvars.rst:31 msgid "This class is used to declare a new Context Variable, e.g.::" -msgstr "" +msgstr "此類別用在宣告新的情境變數,例如:" #: ../../library/contextvars.rst:33 msgid "var: ContextVar[int] = ContextVar('var', default=42)" @@ -53,7 +60,7 @@ msgstr "var: ContextVar[int] = ContextVar('var', default=42)" #: ../../library/contextvars.rst:35 msgid "" "The required *name* parameter is used for introspection and debug purposes." -msgstr "" +msgstr "必要參數 *name* 用於自我檢查(introspection)和除錯。" #: ../../library/contextvars.rst:38 msgid "" @@ -61,6 +68,8 @@ msgid "" "`ContextVar.get` when no value for the variable is found in the current " "context." msgstr "" +"當在目前的情境中找不到變數的值時,:meth:`ContextVar.get` 會回傳 *default* 參數" +"的值,此 *default* 參數只能用關鍵字來定義(關鍵字引數)。" #: ../../library/contextvars.rst:42 msgid "" @@ -69,6 +78,9 @@ msgid "" "context variables which prevents context variables from being properly " "garbage collected." msgstr "" +"**重要:** 情境變數應該在最頂端的模組層級建立,絕對不要在閉包(closure)中建" +"立。 :class:`Context` 物件持有情境變數的強參照,這會阻止情境變數被正確地垃圾" +"回收(garbage collected)。" #: ../../library/contextvars.rst:49 msgid "The name of the variable. This is a read-only property." @@ -76,24 +88,24 @@ msgstr "這個變數的名稱。這是一個唯讀屬性。" #: ../../library/contextvars.rst:55 msgid "Return a value for the context variable for the current context." -msgstr "" +msgstr "回傳當前情境的情境變數值。" #: ../../library/contextvars.rst:57 msgid "" "If there is no value for the variable in the current context, the method " "will:" -msgstr "" +msgstr "如果在當前情境中沒有變數的值,此方法將:" #: ../../library/contextvars.rst:60 msgid "" "return the value of the *default* argument of the method, if provided; or" -msgstr "" +msgstr "回傳方法的 *default* 引數值(如果有提供);或" #: ../../library/contextvars.rst:63 msgid "" "return the default value for the context variable, if it was created with " "one; or" -msgstr "" +msgstr "回傳情境變數的預設值(如果是用情境變量建立的的話);或" #: ../../library/contextvars.rst:66 msgid "raise a :exc:`LookupError`." @@ -102,24 +114,26 @@ msgstr "引發一個 :exc:`LookupError`。" #: ../../library/contextvars.rst:70 msgid "" "Call to set a new value for the context variable in the current context." -msgstr "" +msgstr "在目前的情境中,呼叫以設定情境變數的新值。" #: ../../library/contextvars.rst:73 msgid "" "The required *value* argument is the new value for the context variable." -msgstr "" +msgstr "*value* 屬必要引數,是情境變數的新值。" #: ../../library/contextvars.rst:76 msgid "" "Returns a :class:`~contextvars.Token` object that can be used to restore the " "variable to its previous value via the :meth:`ContextVar.reset` method." msgstr "" +"回傳一個 :class:`~contextvars.Token` 物件,可以用來透過 :meth:`ContextVar." +"reset` 方法還原變數到之前的值。" #: ../../library/contextvars.rst:82 msgid "" "Reset the context variable to the value it had before the :meth:`ContextVar." "set` that created the *token* was used." -msgstr "" +msgstr "將情境變數重設為使用 :meth:`ContextVar.set` 建立 *token* 前的值。" #: ../../library/contextvars.rst:85 msgid "For example::" @@ -136,6 +150,14 @@ msgid "" "# After the reset call the var has no value again, so\n" "# var.get() would raise a LookupError." msgstr "" +"var = ContextVar('var')\n" +"\n" +"token = var.set('new value')\n" +"# 使用 'var「 的程式碼;var.get() 回傳 'new value'。\n" +"var.reset(token)\n" +"\n" +"# 在重設呼叫之後,var 又沒有值了,所以\n" +"# var.get() 會引發 LookupError。" #: ../../library/contextvars.rst:99 msgid "" @@ -143,12 +165,14 @@ msgid "" "be passed to the :meth:`ContextVar.reset` method to revert the value of the " "variable to what it was before the corresponding *set*." msgstr "" +"*Token* 物件由 :meth:`ContextVar.set` 方法回傳。它們可以丟進 :meth:" +"`ContextVar.reset` 方法,用以將變數的值還原為相對應的 *set* 之前的值。" #: ../../library/contextvars.rst:106 msgid "" "A read-only property. Points to the :class:`ContextVar` object that created " "the token." -msgstr "" +msgstr "唯讀屬性。 指向建立 token 的 :class:`ContextVar` 物件。" #: ../../library/contextvars.rst:111 msgid "" @@ -156,24 +180,27 @@ msgid "" "`ContextVar.set` method call that created the token. It points to :attr:" "`Token.MISSING` if the variable was not set before the call." msgstr "" +"唯讀屬性。 值為變數在呼叫 :meth:`ContextVar.set` 方法之前的值。如果變數在呼叫" +"前沒有設定,則指向 :attr:`Token.MISSING`。" #: ../../library/contextvars.rst:118 msgid "A marker object used by :attr:`Token.old_value`." -msgstr "" +msgstr "由 :attr:`Token.old_value` 使用的標記物件。" #: ../../library/contextvars.rst:122 msgid "Manual Context Management" -msgstr "" +msgstr "手動情境管理" #: ../../library/contextvars.rst:126 msgid "Returns a copy of the current :class:`~contextvars.Context` object." -msgstr "" +msgstr "傳回目前 :class:`~contextvars.Context` 物件的複本(copy)。" #: ../../library/contextvars.rst:128 msgid "" "The following snippet gets a copy of the current context and prints all " "variables and their values that are set in it::" msgstr "" +"以下程式碼片段會取得目前情境的複本,並顯示在其中設定的所有變數及其值::" #: ../../library/contextvars.rst:131 msgid "" @@ -189,16 +216,20 @@ msgid "" "contexts with a few context variables and for contexts that have a lot of " "them." msgstr "" +"這個函數具有 *O*\\ (1) 的複雜度,也就是說,對於只有少許情境變數的情境和有大量" +"情境變數的情境,速度都一樣快。" #: ../../library/contextvars.rst:141 msgid "A mapping of :class:`ContextVars ` to their values." -msgstr "" +msgstr ":class:`ContextVars` 到其值的映射。" #: ../../library/contextvars.rst:143 msgid "" "``Context()`` creates an empty context with no values in it. To get a copy " "of the current context use the :func:`~contextvars.copy_context` function." msgstr "" +"``Context()`` 會建立一個沒有值的空情境。要取得目前上下文的複本,請使用 :func:" +"`~contextvars.copy_context` 函式。" #: ../../library/contextvars.rst:147 msgid "" @@ -207,6 +238,9 @@ msgid "" "current thread's stack. All :class:`!Context` objects in the stacks are " "considered to be *entered*." msgstr "" +"每個執行緒都有自己的 :class:`!Context` 物件的有效堆疊(stack)。 :term:" +"`current context` 是目前執行緒堆疊頂端的 :class:`!Context` 物件。 堆疊中的所" +"有 :class:`!Context` 物件都被視為 *entered*。" #: ../../library/contextvars.rst:152 msgid "" @@ -214,6 +248,8 @@ msgid "" "method, makes the context the current context by pushing it onto the top of " "the current thread's context stack." msgstr "" +"*進入* 一個情境,可以藉由呼叫其 :meth:`~Context.run` 方法來完成,此 *進入* 的動" +"作會將一情境推到目前執行緒的情境堆疊的頂端,使該情境成為目前的情境。" #: ../../library/contextvars.rst:156 msgid "" @@ -222,6 +258,9 @@ msgid "" "context to what it was before the context was entered by popping the context " "off the top of the context stack." msgstr "" +"*退出* 目前的情境,可以透過從傳遞給 :meth:`~Context.run` 方法的回呼函式" +"(callback functions)中回傳來完成,這會將目前的情境還原到進入情境之前的狀" +"態,方法是將情境從情境堆疊的頂端彈出。" #: ../../library/contextvars.rst:161 msgid "" @@ -229,16 +268,20 @@ msgid "" "behave in a similar fashion to :func:`threading.local` when values are " "assigned in different threads." msgstr "" +"因為每個執行緒都有自己的情境堆疊,當值在不同的執行緒中被指定時, :class:" +"`ContextVar` 物件的行為與 :func:`threading.local` 相似。" #: ../../library/contextvars.rst:165 msgid "" "Attempting to enter an already entered context, including contexts entered " "in other threads, raises a :exc:`RuntimeError`." msgstr "" +"嘗試輸入已進入的情境,包括在其他執行緒中進入的情境,會引發 :exc:" +"`RuntimeError`。" #: ../../library/contextvars.rst:168 msgid "After exiting a context, it can later be re-entered (from any thread)." -msgstr "" +msgstr "退出情境後,之後可以重新進入(從任何執行緒)。" #: ../../library/contextvars.rst:170 msgid "" @@ -249,10 +292,14 @@ msgid "" "context was entered (if needed, the values can be restored by re-entering " "the context)." msgstr "" +"任何透過 :meth:`ContextVar.set` 方法對 :class:`ContextVar` 值的改變都會記錄在" +"目前的情境中。 :meth:`ContextVar.get` 方法回傳與當前情境相關的值。 退出上下" +"文會有效地還原在進入上下文時對上下文變數所做的任何變更(如果需要,可以透過重" +"新進入上下文來還原值)。" #: ../../library/contextvars.rst:177 msgid "Context implements the :class:`collections.abc.Mapping` interface." -msgstr "" +msgstr "情境實作 :class:`collections.abc.Mapping` 介面。" #: ../../library/contextvars.rst:181 msgid "" @@ -260,10 +307,12 @@ msgid "" "Context. Returns *callable*'s return value, or propagates an exception if " "one occurred." msgstr "" +"進入 Context,執行``callable(*args, **kwargs)``,然後退出 Context。 返回 " +"*callable* 的回傳值,如果發生異常,則傳播異常。" #: ../../library/contextvars.rst:185 msgid "Example:" -msgstr "舉例來說:" +msgstr "例如:" #: ../../library/contextvars.rst:187 msgid "" @@ -298,50 +347,84 @@ msgid "" "# However, outside of 'ctx', 'var' is still set to 'spam':\n" "print(var.get()) # 'spam'" msgstr "" +"import contextvars\n" +"\n" +"var = contextvars.ContextVar('var')\n" +"var.set('spam')\n" +"print(var.get()) # 'spam'\n" +"\n" +"ctx = contextvars.copy_context()\n" +"\n" +"def main():\n" +" # 'var' 之前被設成 'spam'\n" +" # 呼叫 'copy_context()' 和 'ctx.run(main)',所以:\n" +" print(var.get()) # 'spam'\n" +" print(ctx[var]) # 'spam'\n" +"\n" +" var.set('ham')\n" +"\n" +" # 現在, 在把 'var' 的值設成 'ham' 後:\n" +" print(var.get()) # 'ham'\n" +" print(ctx[var]) # 'ham'\n" +"\n" +"# 任何 'main' 函式裡面的對於 'var' 的變更都會\n" +"# 包含在 'ctx 裡:.\n" +"ctx.run(main)\n" +"\n" +"# 'main()' 函式在 'ctx' 情境裡面跑,\n" +"# 所以對於 'var' 的變更會包含在 'ctx' 裡面:\n" +"print(ctx[var]) # 'ham'\n" +"\n" +"# 但是,在 'ctx' 外, 'var' 的值仍然是 'spam':\n" +"print(var.get()) # 'spam'" #: ../../library/contextvars.rst:233 msgid "Return a shallow copy of the context object." -msgstr "" +msgstr "回傳情境物件的淺層複本(shallow copy)。" #: ../../library/contextvars.rst:237 msgid "" "Return ``True`` if the *context* has a value for *var* set; return ``False`` " "otherwise." -msgstr "" +msgstr "如果*情境*裡面有 *var* 的值,則傳回 ``True``;否則傳回 ``False``。" #: ../../library/contextvars.rst:242 msgid "" "Return the value of the *var* :class:`ContextVar` variable. If the variable " "is not set in the context object, a :exc:`KeyError` is raised." msgstr "" +"傳回 *var* :class:`ContextVar` 變數的值。如果該變數並沒有在情境物件中設定,則" +"會引發 :exc:`KeyError` 錯誤。" #: ../../library/contextvars.rst:248 msgid "" "Return the value for *var* if *var* has the value in the context object. " "Return *default* otherwise. If *default* is not given, return ``None``." msgstr "" +"如果 *var* 的值在情境物件中,則回傳 *var* 的值。 否則回傳 *default*。 如果" +"沒有 *default* 值,則回傳``None``。" #: ../../library/contextvars.rst:254 msgid "Return an iterator over the variables stored in the context object." -msgstr "" +msgstr "回傳儲存於情境物件中變數的疊代器。" #: ../../library/contextvars.rst:259 msgid "Return the number of variables set in the context object." -msgstr "" +msgstr "回傳情境物件中的變數個數。" #: ../../library/contextvars.rst:263 msgid "Return a list of all variables in the context object." -msgstr "" +msgstr "回傳情境物件中所有變數的清單。" #: ../../library/contextvars.rst:267 msgid "Return a list of all variables' values in the context object." -msgstr "" +msgstr "回傳情境物件中所有變數的值的清單。" #: ../../library/contextvars.rst:272 msgid "" "Return a list of 2-tuples containing all variables and their values in the " "context object." -msgstr "" +msgstr "回傳情境物件中所有變數與其值的元組(tuple)的清單。" #: ../../library/contextvars.rst:277 msgid "asyncio support" @@ -354,6 +437,9 @@ msgid "" "server, that uses a context variable to make the address of a remote client " "available in the Task that handles that client::" msgstr "" +":mod:`asyncio` 原生支援情境變數,不需任何額外設定。 舉例來說,以下是一個簡單" +"的 echo 伺服器,使用上下文變數讓遠端用客戶端的位址在處理該用戶端的任務中可" +"用:" #: ../../library/contextvars.rst:285 msgid "" @@ -400,3 +486,45 @@ msgid "" "# telnet 127.0.0.1 8081\n" "# curl 127.0.0.1:8081" msgstr "" +"import asyncio\n" +"import contextvars\n" +"\n" +"client_addr_var = contextvars.ContextVar('client_addr')\n" +"\n" +"def render_goodbye():\n" +" # 即使不把目前處理中的客戶端(client)傳入此函式\n" +" # 仍可取得其位址\n" +"\n" +" client_addr = client_addr_var.get()\n" +" return f'Good bye, client @ {client_addr}\\r\\n'.encode()\n" +"\n" +"async def handle_request(reader, writer):\n" +" addr = writer.transport.get_extra_info('socket').getpeername()\n" +" client_addr_var.set(addr)\n" +"\n" +" # 在任何我們呼叫的程式碼中,都有辦法\n" +" # 呼叫 'client_addr_var.get()' 來取得客戶端的位址\n" +"\n" +" while True:\n" +" line = await reader.readline()\n" +" print(line)\n" +" if not line.strip():\n" +" break\n" +"\n" +" writer.write(b'HTTP/1.1 200 OK\\r\\n') # status line\n" +" writer.write(b'\\r\\n') # headers\n" +" writer.write(render_goodbye()) # body\n" +" writer.close()\n" +"\n" +"async def main():\n" +" srv = await asyncio.start_server(\n" +" handle_request, '127.0.0.1', 8081)\n" +"\n" +" async with srv:\n" +" await srv.serve_forever()\n" +"\n" +"asyncio.run(main())\n" +"\n" +"# 您可以使用 telnet 或 curl 測試:\n" +"# telnet 127.0.0.1 8081\n" +"# curl 127.0.0.1:8081" From 1d03bdd3d00f5bc79766e93cf9ea31e20f3b1167 Mon Sep 17 00:00:00 2001 From: husohome Date: Thu, 17 Jul 2025 20:51:50 +0800 Subject: [PATCH 02/10] translated library/contextvars.po; i added my personal interpreations of the original text, otherwise it wouldn't be understandable in chinese --- library/contextvars.po | 75 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/library/contextvars.po b/library/contextvars.po index b103866cdf..518dc0c941 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -5,7 +5,7 @@ msgstr "" "Project-Id-Version: Python 3.13\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-10-31 00:13+0000\n" -"PO-Revision-Date: 2025-07-13 00:28+0800\n" +"PO-Revision-Date: 2025-07-17 20:49+0800\n" "Last-Translator: \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -27,9 +27,10 @@ msgid "" "the :class:`~contextvars.Context` class should be used to manage the current " "context in asynchronous frameworks." msgstr "" -"本模組供 API 來管理、儲存及存取 context-local 狀態。 用 :class:`~contextvars." -"ContextVar` 型別宣告和處理 *情境變數*。 :func:`~contextvars.copy_context` 函式" -"和 :class:`~contextvars.Context` 類別來在非同步框架中管理目前的情境。" +"本模組供 API 來管理、儲存及存取單一情境各自的狀態(context-local state)。 " +"用 :class:`~contextvars.ContextVar` 型別宣告和處理 *情境變數*。 :func:" +"`~contextvars.copy_context` 函式和 :class:`~contextvars.Context` 類別來在非同" +"步框架中管理目前的情境。" #: ../../library/contextvars.rst:17 msgid "" @@ -68,8 +69,8 @@ msgid "" "`ContextVar.get` when no value for the variable is found in the current " "context." msgstr "" -"當在目前的情境中找不到變數的值時,:meth:`ContextVar.get` 會回傳 *default* 參數" -"的值,此 *default* 參數只能用關鍵字來定義(關鍵字引數)。" +"當在目前的情境中找不到變數的值時,:meth:`ContextVar.get` 會回傳 *default* 參" +"數的值,此 *default* 參數只能用關鍵字來定義(關鍵字引數)。" #: ../../library/contextvars.rst:42 msgid "" @@ -78,9 +79,9 @@ msgid "" "context variables which prevents context variables from being properly " "garbage collected." msgstr "" -"**重要:** 情境變數應該在最頂端的模組層級建立,絕對不要在閉包(closure)中建" -"立。 :class:`Context` 物件持有情境變數的強參照,這會阻止情境變數被正確地垃圾" -"回收(garbage collected)。" +"**重要:**\\ 情境變數應該在最頂端的模組層級建立,絕對不要在閉包(closure)中" +"建立。 :class:`Context` 物件持有情境變數的強參照,這會阻止情境變數被正確地垃" +"圾回收(garbage collected)。" #: ../../library/contextvars.rst:49 msgid "The name of the variable. This is a read-only property." @@ -99,17 +100,17 @@ msgstr "如果在當前情境中沒有變數的值,此方法將:" #: ../../library/contextvars.rst:60 msgid "" "return the value of the *default* argument of the method, if provided; or" -msgstr "回傳方法的 *default* 引數值(如果有提供);或" +msgstr "回傳方法的 *default* 引數值(如果有的話);否則" #: ../../library/contextvars.rst:63 msgid "" "return the default value for the context variable, if it was created with " "one; or" -msgstr "回傳情境變數的預設值(如果是用情境變量建立的的話);或" +msgstr "回傳情境變數的預設值(如果是用情境變量建立的的話);否則" #: ../../library/contextvars.rst:66 msgid "raise a :exc:`LookupError`." -msgstr "引發一個 :exc:`LookupError`。" +msgstr "會引發一個 :exc:`LookupError`。" #: ../../library/contextvars.rst:70 msgid "" @@ -126,8 +127,8 @@ msgid "" "Returns a :class:`~contextvars.Token` object that can be used to restore the " "variable to its previous value via the :meth:`ContextVar.reset` method." msgstr "" -"回傳一個 :class:`~contextvars.Token` 物件,可以用來透過 :meth:`ContextVar." -"reset` 方法還原變數到之前的值。" +"回傳一個 :class:`~contextvars.Token` 物件,該物件可以用來還原變數到之前的值," +"透過 :meth:`ContextVar.reset` 方法" #: ../../library/contextvars.rst:82 msgid "" @@ -165,8 +166,8 @@ msgid "" "be passed to the :meth:`ContextVar.reset` method to revert the value of the " "variable to what it was before the corresponding *set*." msgstr "" -"*Token* 物件由 :meth:`ContextVar.set` 方法回傳。它們可以丟進 :meth:" -"`ContextVar.reset` 方法,用以將變數的值還原為相對應的 *set* 之前的值。" +"*Token* 物件由 :meth:`ContextVar.set` 方法回傳,可以丟進 :meth:`ContextVar." +"reset` 方法,用以將變數的值還原為相對應的 *set* 之前的值。" #: ../../library/contextvars.rst:106 msgid "" @@ -193,7 +194,7 @@ msgstr "手動情境管理" #: ../../library/contextvars.rst:126 msgid "Returns a copy of the current :class:`~contextvars.Context` object." -msgstr "傳回目前 :class:`~contextvars.Context` 物件的複本(copy)。" +msgstr "回傳目前 :class:`~contextvars.Context` 物件的複本(copy)。" #: ../../library/contextvars.rst:128 msgid "" @@ -216,7 +217,7 @@ msgid "" "contexts with a few context variables and for contexts that have a lot of " "them." msgstr "" -"這個函數具有 *O*\\ (1) 的複雜度,也就是說,對於只有少許情境變數的情境和有大量" +"這個函式具有 *O*\\ (1) 的複雜度,也就是說,對於只有少許情境變數的情境和有大量" "情境變數的情境,速度都一樣快。" #: ../../library/contextvars.rst:141 @@ -228,7 +229,7 @@ msgid "" "``Context()`` creates an empty context with no values in it. To get a copy " "of the current context use the :func:`~contextvars.copy_context` function." msgstr "" -"``Context()`` 會建立一個沒有值的空情境。要取得目前上下文的複本,請使用 :func:" +"``Context()`` 會建立一個沒有值的空情境。要取得目前情境的複本,請使用 :func:" "`~contextvars.copy_context` 函式。" #: ../../library/contextvars.rst:147 @@ -238,9 +239,9 @@ msgid "" "current thread's stack. All :class:`!Context` objects in the stacks are " "considered to be *entered*." msgstr "" -"每個執行緒都有自己的 :class:`!Context` 物件的有效堆疊(stack)。 :term:" -"`current context` 是目前執行緒堆疊頂端的 :class:`!Context` 物件。 堆疊中的所" -"有 :class:`!Context` 物件都被視為 *entered*。" +"每個執行緒都有自己的 :class:`!Context` 物件中目前主控中的堆疊(stack)。 :" +"term:`current context` 是目前執行緒堆疊頂端的 :class:`!Context` 物件。 堆疊" +"中的所有 :class:`!Context` 物件都被視為\\ *已進入*。" #: ../../library/contextvars.rst:152 msgid "" @@ -248,8 +249,8 @@ msgid "" "method, makes the context the current context by pushing it onto the top of " "the current thread's context stack." msgstr "" -"*進入* 一個情境,可以藉由呼叫其 :meth:`~Context.run` 方法來完成,此 *進入* 的動" -"作會將一情境推到目前執行緒的情境堆疊的頂端,使該情境成為目前的情境。" +"*進入*\\ 一個情境,可以藉由呼叫其 :meth:`~Context.run` 方法來完成,此 \\*進入" +"*\\ 的動作會將一情境推到目前執行緒的情境堆疊的頂端,使該情境成為目前的情境。" #: ../../library/contextvars.rst:156 msgid "" @@ -258,9 +259,9 @@ msgid "" "context to what it was before the context was entered by popping the context " "off the top of the context stack." msgstr "" -"*退出* 目前的情境,可以透過從傳遞給 :meth:`~Context.run` 方法的回呼函式" -"(callback functions)中回傳來完成,這會將目前的情境還原到進入情境之前的狀" -"態,方法是將情境從情境堆疊的頂端彈出。" +"如果你傳遞給 :meth:`~Context.run` 方法的回呼函式(callback functions),該函" +"式回傳之後,就會自動 \\*退出*\\ 目前的情境,這會將目前的情境還原到進入情境之" +"前的狀態,方法是將情境從情境堆疊的頂端彈出。" #: ../../library/contextvars.rst:161 msgid "" @@ -293,13 +294,13 @@ msgid "" "the context)." msgstr "" "任何透過 :meth:`ContextVar.set` 方法對 :class:`ContextVar` 值的改變都會記錄在" -"目前的情境中。 :meth:`ContextVar.get` 方法回傳與當前情境相關的值。 退出上下" -"文會有效地還原在進入上下文時對上下文變數所做的任何變更(如果需要,可以透過重" -"新進入上下文來還原值)。" +"目前的情境中。 :meth:`ContextVar.get` 方法回傳與當前情境相關的值。 退出情境" +"實際造成的效果會像是將其在進入情境時對情境變數所做的任何變一一彈出並還原(如" +"果需要,可以透過重新進入情境來還原值)。" #: ../../library/contextvars.rst:177 msgid "Context implements the :class:`collections.abc.Mapping` interface." -msgstr "情境實作 :class:`collections.abc.Mapping` 介面。" +msgstr "情境(Context)實作了 :class:`collections.abc.Mapping` 介面。" #: ../../library/contextvars.rst:181 msgid "" @@ -307,8 +308,8 @@ msgid "" "Context. Returns *callable*'s return value, or propagates an exception if " "one occurred." msgstr "" -"進入 Context,執行``callable(*args, **kwargs)``,然後退出 Context。 返回 " -"*callable* 的回傳值,如果發生異常,則傳播異常。" +"進入 Context,執行``callable(*args, **kwargs)``,然後退出 Context。 回傳 " +"*callable* 的回傳值,如果發生例外(exception),則傳播例外。" #: ../../library/contextvars.rst:185 msgid "Example:" @@ -386,14 +387,15 @@ msgstr "回傳情境物件的淺層複本(shallow copy)。" msgid "" "Return ``True`` if the *context* has a value for *var* set; return ``False`` " "otherwise." -msgstr "如果*情境*裡面有 *var* 的值,則傳回 ``True``;否則傳回 ``False``。" +msgstr "" +"如果 \\*情境*\\ 裡面有 *var* 的值,則回傳 ``True``,否則回傳 ``False``。" #: ../../library/contextvars.rst:242 msgid "" "Return the value of the *var* :class:`ContextVar` variable. If the variable " "is not set in the context object, a :exc:`KeyError` is raised." msgstr "" -"傳回 *var* :class:`ContextVar` 變數的值。如果該變數並沒有在情境物件中設定,則" +"回傳 *var* :class:`ContextVar` 變數的值。如果該變數並沒有在情境物件中設定,則" "會引發 :exc:`KeyError` 錯誤。" #: ../../library/contextvars.rst:248 @@ -438,8 +440,7 @@ msgid "" "available in the Task that handles that client::" msgstr "" ":mod:`asyncio` 原生支援情境變數,不需任何額外設定。 舉例來說,以下是一個簡單" -"的 echo 伺服器,使用上下文變數讓遠端用客戶端的位址在處理該用戶端的任務中可" -"用:" +"的 echo 伺服器,使用情境變數讓遠端用客戶端的位址在處理該用戶端的任務中可用:" #: ../../library/contextvars.rst:285 msgid "" From 262284112e13560ee4bc60ccfe604a21ca7bcb47 Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:03:02 +0800 Subject: [PATCH 03/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index 518dc0c941..4b75db3243 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -28,7 +28,7 @@ msgid "" "context in asynchronous frameworks." msgstr "" "本模組供 API 來管理、儲存及存取單一情境各自的狀態(context-local state)。 " -"用 :class:`~contextvars.ContextVar` 型別宣告和處理 *情境變數*。 :func:" +"用 :class:`~contextvars.ContextVar` 類別宣告和處理\\ *情境變數*。 :func:" "`~contextvars.copy_context` 函式和 :class:`~contextvars.Context` 類別來在非同" "步框架中管理目前的情境。" From 3f15b3cf4066b0b6307dd84bbcbb4566206b576e Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:03:14 +0800 Subject: [PATCH 04/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index 4b75db3243..d60bda67a1 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -29,7 +29,7 @@ msgid "" msgstr "" "本模組供 API 來管理、儲存及存取單一情境各自的狀態(context-local state)。 " "用 :class:`~contextvars.ContextVar` 類別宣告和處理\\ *情境變數*。 :func:" -"`~contextvars.copy_context` 函式和 :class:`~contextvars.Context` 類別來在非同" +"`~contextvars.copy_context` 函式和 :class:`~contextvars.Context` 類別應在非同" "步框架中管理目前的情境。" #: ../../library/contextvars.rst:17 From 3d0eea2c4a69b1b065f0f177357e5985b16384a2 Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:03:20 +0800 Subject: [PATCH 05/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index d60bda67a1..bdc4bf0353 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -38,7 +38,7 @@ msgid "" "func:`threading.local` to prevent their state from bleeding to other code " "unexpectedly, when used in concurrent code." msgstr "" -"帶有狀態的 Context Manager 應該使用情境變數,不要用 :func:`threading.local`," +"帶有狀態的 Context Manager 應該使用情境變數,而不是 :func:`threading.local`," "才能防止它們的狀態在並行(concurrent)程式碼中使用時意外外溢並干擾到其他程式" "碼。" From d92cf1eb53652dce10bc81ca1dc75f945e8a5222 Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:14:32 +0800 Subject: [PATCH 06/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index bdc4bf0353..c56400560b 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -420,7 +420,7 @@ msgstr "回傳情境物件中所有變數的清單。" #: ../../library/contextvars.rst:267 msgid "Return a list of all variables' values in the context object." -msgstr "回傳情境物件中所有變數的值的清單。" +msgstr "回傳情境物件中所有變數的值的串列。" #: ../../library/contextvars.rst:272 msgid "" From 40ede8dae561bd157f596ab40ecd59acea393594 Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:14:57 +0800 Subject: [PATCH 07/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index c56400560b..6f9e863b4a 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -368,7 +368,7 @@ msgstr "" " print(var.get()) # 'ham'\n" " print(ctx[var]) # 'ham'\n" "\n" -"# 任何 'main' 函式裡面的對於 'var' 的變更都會\n" +"# 'main' 函式對 'var' 所做的任何變更都會\n" "# 包含在 'ctx 裡:.\n" "ctx.run(main)\n" "\n" From 0c012d90d206d6b7cde2d7d1d5dc6baaa5ea92e6 Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:15:11 +0800 Subject: [PATCH 08/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index 6f9e863b4a..baec1adab0 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -372,7 +372,7 @@ msgstr "" "# 包含在 'ctx 裡:.\n" "ctx.run(main)\n" "\n" -"# 'main()' 函式在 'ctx' 情境裡面跑,\n" +"# 'main()' 函式是在 'ctx' 情境中執行,\n" "# 所以對於 'var' 的變更會包含在 'ctx' 裡面:\n" "print(ctx[var]) # 'ham'\n" "\n" From 66a5d0bd1ef962865218e089bd9908b5efe144aa Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:15:54 +0800 Subject: [PATCH 09/10] Update library/contextvars.po Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index baec1adab0..aaf501f0ce 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -358,7 +358,7 @@ msgstr "" "\n" "def main():\n" " # 'var' 之前被設成 'spam'\n" -" # 呼叫 'copy_context()' 和 'ctx.run(main)',所以:\n" +" # 呼叫 'copy_context()' 和 'ctx.run(main)',所以:\n" " print(var.get()) # 'spam'\n" " print(ctx[var]) # 'spam'\n" "\n" From 628c93a1966ad0ec9f55e157d9fff66180af5f9b Mon Sep 17 00:00:00 2001 From: "Nick (Shun-Fu) Hu" Date: Wed, 23 Jul 2025 23:16:17 +0800 Subject: [PATCH 10/10] Update library/contextvars.po nice! thanks! Co-authored-by: Dr.XYZ --- library/contextvars.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/contextvars.po b/library/contextvars.po index aaf501f0ce..20190e5a20 100644 --- a/library/contextvars.po +++ b/library/contextvars.po @@ -373,7 +373,7 @@ msgstr "" "ctx.run(main)\n" "\n" "# 'main()' 函式是在 'ctx' 情境中執行,\n" -"# 所以對於 'var' 的變更會包含在 'ctx' 裡面:\n" +"# 所以對 'var' 的變更會保存在 'ctx' 中:\n" "print(ctx[var]) # 'ham'\n" "\n" "# 但是,在 'ctx' 外, 'var' 的值仍然是 'spam':\n"