From 8a8703e566164a4cb11777d4a3d4fc19ee88ea12 Mon Sep 17 00:00:00 2001 From: Payon Date: Wed, 8 May 2024 20:51:08 +0800 Subject: [PATCH] fix: Inline literal start-string without end-string. feat: to rst:264 Update library/weakref.po Co-authored-by: RockLeon <34214497+rockleona@users.noreply.github.com> Apply suggestions from code review Co-authored-by: RockLeon <34214497+rockleona@users.noreply.github.com> Apply suggestions from code review Co-authored-by: Wei-Hsiang (Matt) Wang fix: Apply suggestions from code review Apply suggestions from code review Co-authored-by: Wei-Hsiang (Matt) Wang --- library/weakref.po | 112 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 96 insertions(+), 16 deletions(-) diff --git a/library/weakref.po b/library/weakref.po index 8baa40ecf8..188a7c20d2 100644 --- a/library/weakref.po +++ b/library/weakref.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-18 00:04+0000\n" -"PO-Revision-Date: 2018-05-23 16:15+0000\n" +"POT-Creation-Date: 2023-10-11 17:13+0000\n" +"PO-Revision-Date: 2024-05-08 22:24+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -17,10 +17,11 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Poedit 3.4.1\n" #: ../../library/weakref.rst:4 msgid ":mod:`weakref` --- Weak references" -msgstr "" +msgstr ":mod:`weakref` --- 弱參照" #: ../../library/weakref.rst:14 msgid "**Source code:** :source:`Lib/weakref.py`" @@ -30,13 +31,14 @@ msgstr "**原始碼:**\\ :source:`Lib/weakref.py`" msgid "" "The :mod:`weakref` module allows the Python programmer to create :dfn:`weak " "references` to objects." -msgstr "" +msgstr ":mod:`weakref` 模組允許 Python 程式設計師建立對物件的 :dfn:`弱參照`。" #: ../../library/weakref.rst:24 msgid "" "In the following, the term :dfn:`referent` means the object which is " "referred to by a weak reference." msgstr "" +"在以下文章中,術語 :dfn:`參照目標 (referent)` 表示被弱參照所參考的物件。" #: ../../library/weakref.rst:27 msgid "" @@ -47,6 +49,10 @@ msgid "" "weak reference may return the object even if there are no strong references " "to it." msgstr "" +"對物件的弱參照不足以使物件保持存在:當對參照目標的唯一剩下的參照是弱參照時,:" +"term:`garbage collection` 可以自由地銷毀參照目標並將其記憶體重新用於其他用" +"途。然而,在物件被確實銷毀之前,即使沒有對該物件的強參照 (strong reference)," +"弱參照也可能會回傳該物件。" #: ../../library/weakref.rst:33 msgid "" @@ -54,6 +60,8 @@ msgid "" "large objects, where it's desired that a large object not be kept alive " "solely because it appears in a cache or mapping." msgstr "" +"弱參照的主要用途是實作保存大型物件的快取或對映,其不希望大型物件僅僅因為它出" +"現在快取或對映中而保持存在。" #: ../../library/weakref.rst:37 msgid "" @@ -70,6 +78,15 @@ msgid "" "collection can reclaim the object, and its corresponding entries in weak " "mappings are simply deleted." msgstr "" +"例如,如果你有許多大型的二進位影像物件,你可能會想要為每個物件關聯 " +"(associate) 一個名稱。如果你使用 Python 字典將名稱對映到影像,或將影像對映到" +"名稱,則影像物件將保持存活,僅因為它們在字典中作為值 (value) 或鍵 (key) 出" +"現。:mod:`weakref` 模組提供的 :class:`WeakKeyDictionary` 和 :class:" +"`WeakValueDictionary` 類別是另一種選擇,它們使用弱參照來建構對映,這些對映不" +"會僅因為物件出現在對映物件中而使物件保持存活。例如,如果一個影像物件是 :" +"class:`WeakValueDictionary` 中的一個值,那麼當對該影像物件最後的參照是弱對映 " +"(weak mapping) 所持有的弱參照時,垃圾回收 (garbage collection) 可以回收該物" +"件,且其對應的條目在弱對映中會被完全地刪除。" #: ../../library/weakref.rst:50 msgid "" @@ -80,6 +97,10 @@ msgid "" "class:`set` interface, but keeps weak references to its elements, just like " "a :class:`WeakKeyDictionary` does." msgstr "" +":class:`WeakKeyDictionary` 和 :class:`WeakValueDictionary` 在其實作中使用弱參" +"照,在弱參照上設定回呼函式,此弱參照在垃圾回收取回鍵或值時通知弱字典。:class:" +"`WeakSet` 實作了 :class:`set` 介面,但保留對其元素的弱參照,就像 :class:" +"`WeakKeyDictionary` 一樣。" #: ../../library/weakref.rst:57 msgid "" @@ -89,6 +110,9 @@ msgid "" "the module automatically ensures that the finalizer remains alive until the " "object is collected." msgstr "" +":class:`finalize` 提供了一種直接的方法來註冊在物件被垃圾回收時呼叫的清理函" +"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被收集前會自動確" +"保終結函式 (finalizer) 保持存活。" #: ../../library/weakref.rst:63 msgid "" @@ -97,6 +121,9 @@ msgid "" "your own weak references directly. The low-level machinery is exposed by " "the :mod:`weakref` module for the benefit of advanced uses." msgstr "" +"大多數程式應該發現使用這些弱容器種類之一或 :class:`finalize` 就足夠了—通常不" +"需要直接建立自己的弱參照。低層級的機制由 :mod:`weakref` 模組公開,以利於進階" +"用途。" #: ../../library/weakref.rst:68 msgid "" @@ -106,28 +133,38 @@ msgid "" "object>`, :term:`generators `, type objects, sockets, arrays, " "deques, regular expression pattern objects, and code objects." msgstr "" +"並非所有物件都可以被弱參照。支援弱參照的物件包括類別實例、用 Python (但不是" +"C)編寫的函式、實例方法、集合、凍結集合 (frozenset)、一些\\ :term:`檔案物件 " +"`、:term:`產生器 `、類型物件、socket、陣列、雙向佇" +"列、正規表示式模式物件和程式碼物件。" #: ../../library/weakref.rst:74 msgid "Added support for thread.lock, threading.Lock, and code objects." -msgstr "" +msgstr "新增了對 thread.lock、threading.Lock 和程式碼物件的支援。" #: ../../library/weakref.rst:77 msgid "" "Several built-in types such as :class:`list` and :class:`dict` do not " "directly support weak references but can add support through subclassing::" msgstr "" +"一些內建型別,例如 :class:`list` 和 :class:`dict` 不直接支援弱參照,但可以透" +"過子類別化來支援: ::" #: ../../library/weakref.rst:87 msgid "" "Other built-in types such as :class:`tuple` and :class:`int` do not support " "weak references even when subclassed." msgstr "" +"其他內建型別,例如 :class:`tuple` 和 :class:`int` 即使在子類別化時也不支援弱" +"參照。" #: ../../library/weakref.rst:90 msgid "" "Extension types can easily be made to support weak references; see :ref:" "`weakref-support`." msgstr "" +"擴充型別 (extension type) 可以輕易地支援弱參照;請參閱 :ref:`weakref-" +"support`。" #: ../../library/weakref.rst:93 msgid "" @@ -136,6 +173,9 @@ msgid "" "of strings in the ``__slots__`` declaration. See :ref:`__slots__ " "documentation ` for details." msgstr "" +"當為給定的型別定義 ``__slots__`` 時,弱參照支援將被停用,除非 " +"``'__weakref__'`` 字串也存在於 ``__slots__`` 宣告的字串序列中。詳情請參閱 :" +"ref:`__slots__ 文件 `。" #: ../../library/weakref.rst:100 msgid "" @@ -148,6 +188,11 @@ msgid "" "passed as the only parameter to the callback; the referent will no longer be " "available." msgstr "" +"傳回對 *object* 的弱參照。如果參照目標仍存活,則可以透過呼叫參照物件來取回原" +"始物件;如果參照目標已不存活,呼叫參照物件將導致 :const:`None` 被回傳。如果 " +"*callback* 被提供而非 :const:`None`,且回傳的弱參照物件仍存活,那麼當物件即將" +"被終結 (finalize) 時,回呼將被呼叫;弱參照物件將作為唯一的參數傳遞給回呼;參" +"照物件將不再可用。" #: ../../library/weakref.rst:108 msgid "" @@ -155,6 +200,8 @@ msgid "" "object. Callbacks registered for each weak reference will be called from the " "most recently registered callback to the oldest registered callback." msgstr "" +"為同一個物件建構多個弱參照是可行的。為每個弱參照註冊的回呼將按照最新到最舊註" +"冊的回呼順序來被呼叫。" #: ../../library/weakref.rst:112 msgid "" @@ -162,6 +209,8 @@ msgid "" "output, but cannot be propagated; they are handled in exactly the same way " "as exceptions raised from an object's :meth:`~object.__del__` method." msgstr "" +"回呼引發的例外將在標準錯誤輸出中被註明,但無法被傳播;它們的處理方式與物件" +"的 :meth:`~object.__del__` 方法引發的例外完全相同。" #: ../../library/weakref.rst:116 msgid "" @@ -170,6 +219,9 @@ msgid "" "`hash` is called the first time only after the *object* was deleted, the " "call will raise :exc:`TypeError`." msgstr "" +"如果 *object* 是\\ :term:`可雜湊的 `,那麼弱參照就是可雜湊的。即使" +"在 *object* 被刪除後,它們仍將保留其雜湊值。如果僅在 *object* 刪除後才第一次" +"呼叫 :func:`hash`,則該呼叫將引發 :exc:`TypeError`。" #: ../../library/weakref.rst:121 msgid "" @@ -179,10 +231,13 @@ msgid "" "referent has been deleted, the references are equal only if the reference " "objects are the same object." msgstr "" +"弱參照支援相等性的測試,但不支援排序。如果參照目標仍存活,則兩個參照與其參照" +"目標具有相同的相等關係(無論 *callback* 如何)。如果任一參照目標已被刪除,則" +"僅當參照物件是同一物件時,參照才相等。" #: ../../library/weakref.rst:126 msgid "This is a subclassable type rather than a factory function." -msgstr "" +msgstr "這是一個可子類別化的型別,而不是一個工廠函式。" #: ../../library/weakref.rst:130 msgid "" @@ -190,6 +245,8 @@ msgid "" "weakref. If there is no callback or if the referent of the weakref is no " "longer alive then this attribute will have value ``None``." msgstr "" +"此唯讀屬性回傳目前與弱參照關聯的回呼。如果沒有回呼或弱參照的參照目標已不存" +"活,那麼該屬性的值為 ``None``。" #: ../../library/weakref.rst:134 msgid "Added the :attr:`__callback__` attribute." @@ -207,29 +264,35 @@ msgid "" "keys. *callback* is the same as the parameter of the same name to the :func:" "`ref` function." msgstr "" +"傳回一個使用弱參照的 *object* 的代理 (proxy)。這支援在大多數情境中使用代理," +"而不需要對弱參照物件明確地取消參照。回傳的物件將具有 ``ProxyType`` 或 " +"``CallableProxyType`` 型別,具體取決於 *object* 是否為可呼叫物件。無論參照目" +"標如何,代理物件都不是 :term:`hashable`;這避免了與其基本可變物件本質相關的許" +"多問題,並阻止它們作為字典的鍵被使用。*callback* 與 :func:`ref` 函式的同名參" +"數是相同的。" #: ../../library/weakref.rst:149 msgid "" "Accessing an attribute of the proxy object after the referent is garbage " "collected raises :exc:`ReferenceError`." -msgstr "" +msgstr "在參照目標被垃圾回收後存取代理物件的屬性會引發 :exc:`ReferenceError`。" #: ../../library/weakref.rst:152 msgid "" "Extended the operator support on proxy objects to include the matrix " "multiplication operators ``@`` and ``@=``." -msgstr "" +msgstr "提供對代理物件的運算子支援,以包括矩陣乘法運算子 ``@`` 和 ``@=``。" #: ../../library/weakref.rst:159 msgid "" "Return the number of weak references and proxies which refer to *object*." -msgstr "" +msgstr "回傳參照 *object* 的弱參照和代理的數量。" #: ../../library/weakref.rst:164 msgid "" "Return a list of all weak reference and proxy objects which refer to " "*object*." -msgstr "" +msgstr "回傳參照 *object* 的所有弱參照和代理物件的一個串列。" #: ../../library/weakref.rst:169 msgid "" @@ -239,6 +302,9 @@ msgid "" "of an application without adding attributes to those objects. This can be " "especially useful with objects that override attribute accesses." msgstr "" +"弱參照鍵的對映類別。當不再有對鍵的強參照時,字典中的條目將被丟棄。這可用於將" +"附加資料與應用程式其他部分擁有的物件相關聯,而無需向這些物件新增屬性。這對於" +"覆蓋屬性存取的物件特別有用。" #: ../../library/weakref.rst:175 msgid "" @@ -247,10 +313,13 @@ msgid "" "not replace the existing key. Due to this, when the reference to the " "original key is deleted, it also deletes the entry in the dictionary::" msgstr "" +"請注意,當將與現有鍵具有相同值的鍵(但識別性不相等)插入字典時,它會替換該" +"值,但不會替換現有鍵。因此,當刪除對原始鍵的參照時,它也會刪除字典中的條" +"目: ::" #: ../../library/weakref.rst:188 msgid "A workaround would be to remove the key prior to reassignment::" -msgstr "" +msgstr "一個變通的解法是在重新賦值 (reassignment) 之前刪除鍵: ::" #: ../../library/weakref.rst:199 msgid "Added support for ``|`` and ``|=`` operators, specified in :pep:`584`." @@ -265,37 +334,44 @@ msgid "" "references that will cause the garbage collector to keep the keys around " "longer than needed." msgstr "" +":class:`WeakKeyDictionary` 物件有一個直接公開內部參照的附加方法。參照在被使用" +"時不保證是 \"存活的\",因此在使用之前需要檢查呼叫參照的結果。這可以用來防止建" +"立會導致垃圾回收器保留鍵的時間超過其所需時間的參照。" #: ../../library/weakref.rst:212 msgid "Return an iterable of the weak references to the keys." -msgstr "" +msgstr "傳回對鍵的弱參照的可疊代物件。" #: ../../library/weakref.rst:217 msgid "" "Mapping class that references values weakly. Entries in the dictionary will " "be discarded when no strong reference to the value exists any more." -msgstr "" +msgstr "弱參照值的對映類別。當不再存在對值的強參照時,字典中的條目將被丟棄。" #: ../../library/weakref.rst:220 msgid "" "Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`." -msgstr "" +msgstr "新增對 ``|`` 和 ``|=`` 運算子的支持,如 :pep:`584` 中所說明。" #: ../../library/weakref.rst:223 msgid "" ":class:`WeakValueDictionary` objects have an additional method that has the " "same issues as the :meth:`WeakKeyDictionary.keyrefs` method." msgstr "" +":class:`WeakValueDictionary` 物件有一個附加方法,它與 :meth:" +"`WeakKeyDictionary.keyrefs` 方法有相同的問題。" #: ../../library/weakref.rst:229 msgid "Return an iterable of the weak references to the values." -msgstr "" +msgstr "傳回對值的弱參照的可疊代物件。" #: ../../library/weakref.rst:234 msgid "" "Set class that keeps weak references to its elements. An element will be " "discarded when no strong reference to it exists any more." msgstr "" +"保留對其元素的弱參照的集合類別。當不再存在對某個元素的強參照時,該元素將被丟" +"棄。" #: ../../library/weakref.rst:240 msgid "" @@ -305,12 +381,16 @@ msgid "" "hold of it. :class:`WeakMethod` has special code to recreate the bound " "method until either the object or the original function dies::" msgstr "" +"一個特製的 :class:`ref` 子類別,其模擬對繫結方法 (bound method) (即在類別上" +"定義並在實例上查找的方法)的弱參照。由於繫結方法是短暫存在的,因此標準弱參照" +"無法保留它。:class:`WeakMethod` 有特殊的程式碼來重新建立繫結方法,直到物件或" +"原始函式死亡: ::" #: ../../library/weakref.rst:264 msgid "" "*callback* is the same as the parameter of the same name to the :func:`ref` " "function." -msgstr "" +msgstr "*callback* 與 :func:`ref` 函式的同名參數是相同的。" #: ../../library/weakref.rst:270 msgid ""