From 29fd773c6785f7f7e959796c88d87c1275be61c2 Mon Sep 17 00:00:00 2001 From: Payon Date: Thu, 23 May 2024 13:21:26 +0800 Subject: [PATCH] translate-weakref (#904) --- library/weakref.po | 111 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 24 deletions(-) diff --git a/library/weakref.po b/library/weakref.po index 188a7c20d2..4ff792d9fb 100644 --- a/library/weakref.po +++ b/library/weakref.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-10-11 17:13+0000\n" -"PO-Revision-Date: 2024-05-08 22:24+0800\n" +"PO-Revision-Date: 2024-05-22 20:58+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -17,7 +17,7 @@ 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" +"X-Generator: Poedit 3.4.4\n" #: ../../library/weakref.rst:4 msgid ":mod:`weakref` --- Weak references" @@ -111,8 +111,8 @@ msgid "" "object is collected." msgstr "" ":class:`finalize` 提供了一種直接的方法來註冊在物件被垃圾回收時呼叫的清理函" -"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被收集前會自動確" -"保終結函式 (finalizer) 保持存活。" +"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被回收前會自動確" +"保最終化器 (finalizer) 保持存活。" #: ../../library/weakref.rst:63 msgid "" @@ -188,11 +188,11 @@ msgid "" "passed as the only parameter to the callback; the referent will no longer be " "available." msgstr "" -"傳回對 *object* 的弱參照。如果參照目標仍存活,則可以透過呼叫參照物件來取回原" +"回傳對 *object* 的弱參照。如果參照目標仍存活,則可以透過呼叫參照物件來取回原" "始物件;如果參照目標已不存活,呼叫參照物件將導致 :const:`None` 被回傳。如果 " "*callback* 被提供而非 :const:`None`,且回傳的弱參照物件仍存活,那麼當物件即將" -"被終結 (finalize) 時,回呼將被呼叫;弱參照物件將作為唯一的參數傳遞給回呼;參" -"照物件將不再可用。" +"被最終化 (finalize) 時,回呼將被呼叫;弱參照物件將作為唯一的參數傳遞給回呼;" +"參照物件將不再可用。" #: ../../library/weakref.rst:108 msgid "" @@ -264,7 +264,7 @@ msgid "" "keys. *callback* is the same as the parameter of the same name to the :func:" "`ref` function." msgstr "" -"傳回一個使用弱參照的 *object* 的代理 (proxy)。這支援在大多數情境中使用代理," +"回傳一個使用弱參照的 *object* 的代理 (proxy)。這支援在大多數情境中使用代理," "而不需要對弱參照物件明確地取消參照。回傳的物件將具有 ``ProxyType`` 或 " "``CallableProxyType`` 型別,具體取決於 *object* 是否為可呼叫物件。無論參照目" "標如何,代理物件都不是 :term:`hashable`;這避免了與其基本可變物件本質相關的許" @@ -340,7 +340,7 @@ msgstr "" #: ../../library/weakref.rst:212 msgid "Return an iterable of the weak references to the keys." -msgstr "傳回對鍵的弱參照的可疊代物件。" +msgstr "回傳對鍵的弱參照的可疊代物件。" #: ../../library/weakref.rst:217 msgid "" @@ -363,7 +363,7 @@ msgstr "" #: ../../library/weakref.rst:229 msgid "Return an iterable of the weak references to the values." -msgstr "傳回對值的弱參照的可疊代物件。" +msgstr "回傳對值的弱參照的可疊代物件。" #: ../../library/weakref.rst:234 msgid "" @@ -399,6 +399,9 @@ msgid "" "always survive until the reference object is collected, greatly simplifying " "lifecycle management." msgstr "" +"回傳可呼叫的最終化器物件,此物件在 *obj* 被垃圾回收時會被呼叫。與一般的弱參照" +"不同,最終化器將始終存在,直到參照物件被回收為止,從而大大簡化了生命週期管" +"理。" #: ../../library/weakref.rst:275 msgid "" @@ -407,6 +410,9 @@ msgid "" "finalizer returns the result of evaluating ``func(*arg, **kwargs)``, whereas " "calling a dead finalizer returns :const:`None`." msgstr "" +"最終化器在被呼叫(明確呼叫或在垃圾回收時)之前被視為\\ *存活*,之後它就會\\ *" +"死亡*。呼叫存活的最終化器會回傳 ``func(*arg, **kwargs)`` 的計算結果,而呼叫死" +"亡的最終化器會回傳 :const:`None`。" #: ../../library/weakref.rst:280 msgid "" @@ -415,6 +421,8 @@ msgid "" "handled in the same way as exceptions raised from an object's :meth:`~object." "__del__` method or a weak reference's callback." msgstr "" +"垃圾回收期間最終化器回呼引發的例外會在標準錯誤輸出中顯示,但無法傳播。它們的" +"處理方式與從物件的 :meth:`~object.__del__` 方法或弱參照的回呼引發的例外相同。" #: ../../library/weakref.rst:286 msgid "" @@ -422,6 +430,8 @@ msgid "" "attr:`atexit` attribute has been set to false. They are called in reverse " "order of creation." msgstr "" +"當程式結束時,除非該最終化器的 :attr:`atexit` 屬性已被設定為 false,否則每個" +"存活的最終化器會被呼叫。它們以與建立相反的順序被呼叫。" #: ../../library/weakref.rst:290 msgid "" @@ -429,28 +439,36 @@ msgid "" "term:`interpreter shutdown` when module globals are liable to have been " "replaced by :const:`None`." msgstr "" +"當模組的 globals 可能被 :const:`None` 取代時,最終化器永遠不會在 :term:" +"`interpreter shutdown` 的後期調用(invoke)其回呼。" #: ../../library/weakref.rst:296 msgid "" "If *self* is alive then mark it as dead and return the result of calling " "``func(*args, **kwargs)``. If *self* is dead then return :const:`None`." msgstr "" +"如果 *self* 仍存活,則將其標記為死亡並回傳呼叫 ``func(*args, **kwargs)`` 的結" +"果。如果 *self* 已死亡,則回傳 :const:`None`。" #: ../../library/weakref.rst:302 msgid "" "If *self* is alive then mark it as dead and return the tuple ``(obj, func, " "args, kwargs)``. If *self* is dead then return :const:`None`." msgstr "" +"如果 *self* 仍存活,則將其標記為死亡並回傳元組 ``(obj, func, args, " +"kwargs)``。如果 *self* 已死亡,則回傳 :const:`None`。" #: ../../library/weakref.rst:308 msgid "" "If *self* is alive then return the tuple ``(obj, func, args, kwargs)``. If " "*self* is dead then return :const:`None`." msgstr "" +"如果 *self* 仍存活,則回傳元組 ``(obj, func, args, kwargs)``。如果 *self* 已" +"死亡,則回傳 :const:`None`。" #: ../../library/weakref.rst:313 msgid "Property which is true if the finalizer is alive, false otherwise." -msgstr "" +msgstr "如果最終化器仍存活,則屬性為 true,否則為 false。" #: ../../library/weakref.rst:317 msgid "" @@ -458,6 +476,8 @@ msgid "" "exits, it calls all remaining live finalizers for which :attr:`.atexit` is " "true. They are called in reverse order of creation." msgstr "" +"一個可寫的布林屬性,預設為 true。當程式結束時,它會呼叫 :attr:`.atexit` 為 " +"true 的所有剩餘且仍存活的最終化器。它們以與建立相反的順序被呼叫。" #: ../../library/weakref.rst:324 msgid "" @@ -466,18 +486,20 @@ msgid "" "will never be garbage collected. In particular, *func* should not be a " "bound method of *obj*." msgstr "" +"確保 *func*、*args* 和 *kwargs* 不直接或間接擁有對 *obj* 的任何參照非常重要," +"否則 *obj* 將永遠不會被垃圾回收。尤其 *func* 不應該是 *obj* 的繫結方法。" #: ../../library/weakref.rst:334 msgid "The type object for weak references objects." -msgstr "" +msgstr "弱參照物件的型別物件。" #: ../../library/weakref.rst:339 msgid "The type object for proxies of objects which are not callable." -msgstr "" +msgstr "非可呼叫物件的代理的型別物件。" #: ../../library/weakref.rst:344 msgid "The type object for proxies of callable objects." -msgstr "" +msgstr "可呼叫物件的代理的型別物件。" #: ../../library/weakref.rst:349 msgid "" @@ -485,20 +507,22 @@ msgid "" "simpler to test if an object is a proxy without being dependent on naming " "both proxy types." msgstr "" +"包含代理的所有型別物件的序列。這可以讓測試物件是否為代理變得更簡單,而無需依" +"賴命名兩種代理型別。" #: ../../library/weakref.rst:356 msgid ":pep:`205` - Weak References" -msgstr "" +msgstr ":pep:`205` - 弱參照" #: ../../library/weakref.rst:357 msgid "" "The proposal and rationale for this feature, including links to earlier " "implementations and information about similar features in other languages." -msgstr "" +msgstr "此功能的提案和理由,包括早期實作的連結以及其他語言中類似功能的資訊。" #: ../../library/weakref.rst:364 msgid "Weak Reference Objects" -msgstr "" +msgstr "弱參照物件" #: ../../library/weakref.rst:366 msgid "" @@ -506,12 +530,14 @@ msgid "" "__callback__`. A weak reference object allows the referent to be obtained, " "if it still exists, by calling it:" msgstr "" +"弱參照物件除了 :attr:`ref.__callback__` 之外沒有任何方法和屬性。弱參照物件允" +"許透過呼叫來獲取參照目標(如果它仍然存在):" #: ../../library/weakref.rst:380 msgid "" "If the referent no longer exists, calling the reference object returns :" "const:`None`:" -msgstr "" +msgstr "如果參照目標不再存活,則呼叫參照物件將回傳 :const:`None`:" #: ../../library/weakref.rst:387 msgid "" @@ -519,6 +545,8 @@ msgid "" "expression ``ref() is not None``. Normally, application code that needs to " "use a reference object should follow this pattern::" msgstr "" +"應該使用運算式 ``ref() is not None`` 來測試弱參照物件是否仍然存活。需要使用參" +"照物件的應用程式程式碼通常應遵循以下模式: ::" #: ../../library/weakref.rst:400 msgid "" @@ -527,6 +555,9 @@ msgid "" "invalidated before the weak reference is called; the idiom shown above is " "safe in threaded applications as well as single-threaded applications." msgstr "" +"使用對「活性 (liveness)」的單獨測試會在執行緒應用程式中建立競爭條件 (race " +"condition);另一個執行緒可能在弱參照被呼叫之前讓該弱參照失效;上方顯示的慣用" +"作法在執行緒應用程式和單執行緒應用程式中都是安全的。" #: ../../library/weakref.rst:405 msgid "" @@ -537,6 +568,10 @@ msgid "" "reference, but could also be used to insert additional processing on calls " "to retrieve the referent." msgstr "" +"可以透過子類別化來建立 :class:`ref` 物件的特殊版本。這在 :class:" +"`WeakValueDictionary` 的實作中被使用,以減少對映中每個條目的記憶體開銷。這對" +"於將附加資訊與參照相關聯最有用,但也可用於在呼叫上插入附加處理以檢索參照目" +"標。" #: ../../library/weakref.rst:411 msgid "" @@ -544,6 +579,8 @@ msgid "" "additional information about an object and affect the value that's returned " "when the referent is accessed::" msgstr "" +"這個範例展示如何使用 :class:`ref` 的子類別來儲存有關物件的附加資訊並影響存取" +"參照目標時回傳的值: ::" #: ../../library/weakref.rst:438 msgid "Example" @@ -556,10 +593,13 @@ msgid "" "other data structures without forcing the objects to remain alive, but the " "objects can still be retrieved by ID if they do." msgstr "" +"這個簡單的範例展示了應用程式如何使用物件 ID 來檢索它以前見過​​的物件。物件的 " +"ID 之後可以在其他資料結構中使用,而不必強制物件保持存活,但如果這樣做,仍然可" +"以透過 ID 檢索物件。" #: ../../library/weakref.rst:465 msgid "Finalizer Objects" -msgstr "" +msgstr "最終化器物件" #: ../../library/weakref.rst:467 msgid "" @@ -567,12 +607,14 @@ msgid "" "register a callback without needing to preserve the returned finalizer " "object. For instance" msgstr "" +"使用 :class:`finalize` 的最大優點是可以輕鬆註冊回呼,而無需保留回傳的最終化器" +"物件。例如" #: ../../library/weakref.rst:481 msgid "" "The finalizer can be called directly as well. However the finalizer will " "invoke the callback at most once." -msgstr "" +msgstr "最終化器也可以直接被呼叫。然而,最終化器最多會調用回呼一次。" #: ../../library/weakref.rst:497 msgid "" @@ -580,6 +622,8 @@ msgid "" "This kills the finalizer and returns the arguments passed to the constructor " "when it was created." msgstr "" +"你可以使用最終化器的 :meth:`~finalize.detach` 方法來取消註冊最終化器。這會殺" +"死最終化器並回傳建立建構函式時傳遞給建構函式的引數。" #: ../../library/weakref.rst:511 msgid "" @@ -587,10 +631,12 @@ msgid "" "finalizer will be called when the program exits if it is still alive. For " "instance" msgstr "" +"除非你將 :attr:`~finalize.atexit` 屬性設為 :const:`False`,否則當程式結束時," +"最終化器將會被呼叫如果其仍然存在。例如" #: ../../library/weakref.rst:526 msgid "Comparing finalizers with :meth:`~object.__del__` methods" -msgstr "" +msgstr "最終化器與 :meth:`~object.__del__` 方法的比較" #: ../../library/weakref.rst:528 msgid "" @@ -598,24 +644,27 @@ msgid "" "directories. The directories should be deleted with their contents when the " "first of the following events occurs:" msgstr "" +"假設我們要建立一個類別,其實例代表臨時目錄。當以下任一事件發生時,應刪除目錄" +"及其內容:" #: ../../library/weakref.rst:532 msgid "the object is garbage collected," -msgstr "" +msgstr "該物件被垃圾回收," #: ../../library/weakref.rst:533 msgid "the object's :meth:`!remove` method is called, or" -msgstr "" +msgstr "該物件的 :meth:`!remove` 方法被呼叫,或者" #: ../../library/weakref.rst:534 msgid "the program exits." -msgstr "" +msgstr "程式結束。" #: ../../library/weakref.rst:536 msgid "" "We might try to implement the class using a :meth:`~object.__del__` method " "as follows::" msgstr "" +"我們可以用以下的方式來嘗試使用 :meth:`~object.__del__` 方法實作該類別: ::" #: ../../library/weakref.rst:555 msgid "" @@ -624,6 +673,9 @@ msgid "" "longer forced to :const:`None` during :term:`interpreter shutdown`. So this " "code should work without any issues on CPython." msgstr "" +"從 Python 3.4 開始,:meth:`~object.__del__` 方法不再阻止參照循環 (reference " +"cycle) 被垃圾回收,並且在 :term:`interpreter shutdown` 期間不再強制將模組的 " +"globals 設為 :const:`None`。所以這段程式碼在 CPython 上應該可以正常運作。" #: ../../library/weakref.rst:560 msgid "" @@ -631,6 +683,8 @@ msgid "" "implementation specific, since it depends on internal details of the " "interpreter's garbage collector implementation." msgstr "" +"然而,眾所周知,對 :meth:`~object.__del__` 方法的處理是特地實作的,因為它依賴" +"於直譯器的垃圾回收器實作的內部細節。" #: ../../library/weakref.rst:564 msgid "" @@ -638,6 +692,8 @@ msgid "" "the specific functions and objects that it needs, rather than having access " "to the full state of the object::" msgstr "" +"更耐用的替代方案可以是定義一個最終化器,其僅參照需要的特定函式和物件,而不是" +"存取物件的完整狀態: ::" #: ../../library/weakref.rst:580 msgid "" @@ -645,6 +701,8 @@ msgid "" "needs to clean up the directory appropriately. If the object never gets " "garbage collected the finalizer will still be called at exit." msgstr "" +"定義如下,我們的最終化器僅接收對適當清理目錄所需的詳細資訊的參照。如果物件從" +"未被垃圾回收,則最終化器仍將在結束時被呼叫。" #: ../../library/weakref.rst:584 msgid "" @@ -652,6 +710,8 @@ msgid "" "register finalizers for classes where the definition is controlled by a " "third party, such as running code when a module is unloaded::" msgstr "" +"基於 weakref 的最終化器的另一個優點是它們可用於為定義由第三方控制的類別註冊最" +"終化器,例如在卸載模組時執行程式碼: ::" #: ../../library/weakref.rst:596 msgid "" @@ -660,3 +720,6 @@ msgid "" "at exit. However, in a daemonic thread :func:`atexit.register`, ``try: ... " "finally: ...`` and ``with: ...`` do not guarantee that cleanup occurs either." msgstr "" +"如果在程式結束時在常駐的 (daemonic) 執行緒中建立最終化器物件,則最終化器有可" +"能在結束時不會被呼叫。然而,在常駐的執行緒中 :func:`atexit.register`、" +"``try: ... finally: ...`` 和 ``with: ...`` 也不保證清理會發生。"