Thanks to visit codestin.com
Credit goes to github.com

Skip to content

translate-weakref #904

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

Merged
merged 4 commits into from
May 23, 2024
Merged
Changes from 2 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
104 changes: 84 additions & 20 deletions library/weakref.po
Original file line number Diff line number Diff line change
Expand Up @@ -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-17 00:33+0800\n"
"Last-Translator: Adrian Liaw <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All @@ -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"
Expand Down Expand Up @@ -111,8 +111,8 @@ msgid ""
"object is collected."
msgstr ""
":class:`finalize` 提供了一種直接的方法來註冊在物件被垃圾回收時呼叫的清理函"
"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被收集前會自動確"
"保終結函式 (finalizer) 保持存活。"
"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被回收前會自動確"
"保最終化函式 (finalizer) 保持存活。"

#: ../../library/weakref.rst:63
msgid ""
Expand Down Expand Up @@ -191,8 +191,8 @@ msgstr ""
"傳回對 *object* 的弱參照。如果參照目標仍存活,則可以透過呼叫參照物件來取回原"
"始物件;如果參照目標已不存活,呼叫參照物件將導致 :const:`None` 被回傳。如果 "
"*callback* 被提供而非 :const:`None`,且回傳的弱參照物件仍存活,那麼當物件即將"
"被終結 (finalize) 時,回呼將被呼叫;弱參照物件將作為唯一的參數傳遞給回呼;"
"照物件將不再可用。"
"被最終化 (finalize) 時,回呼將被呼叫;弱參照物件將作為唯一的參數傳遞給回呼;"
"參照物件將不再可用。"

#: ../../library/weakref.rst:108
msgid ""
Expand Down Expand Up @@ -399,6 +399,9 @@ msgid ""
"always survive until the reference object is collected, greatly simplifying "
"lifecycle management."
msgstr ""
"傳回可呼叫的最終化函式物件,此物件在 *obj* 被垃圾回收時會被呼叫。與一般的弱參"
"照不同,最終化函式將始終存在,直到參照物件被回收為止,從而大大簡化了生命週期"
"管理。"

#: ../../library/weakref.rst:275
msgid ""
Expand All @@ -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 ""
Expand All @@ -415,49 +421,64 @@ 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 ""
"When the program exits, each remaining live finalizer is called unless its :"
"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 ""
"A finalizer will never invoke its callback during the later part of the :"
"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 ""
"A writable boolean property which by default is true. When the program "
"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 ""
Expand All @@ -466,59 +487,67 @@ 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 ""
"Sequence containing all the type objects for proxies. This can make it "
"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 ""
"Weak reference objects have no methods and no attributes besides :attr:`ref."
"__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 ""
"Testing that a weak reference object is still live should be done using the "
"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 ""
Expand All @@ -527,6 +556,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 ""
Expand All @@ -537,13 +569,19 @@ 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 ""
"This example shows how a subclass of :class:`ref` can be used to store "
"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"
Expand All @@ -556,66 +594,78 @@ 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 ""
"The main benefit of using :class:`finalize` is that it makes it simple to "
"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 ""
"You can unregister a finalizer using its :meth:`~finalize.detach` method. "
"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 ""
"Unless you set the :attr:`~finalize.atexit` attribute to :const:`False`, a "
"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 ""
"Suppose we want to create a class whose instances represent temporary "
"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 ""
Expand All @@ -624,34 +674,45 @@ 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 ""
"However, handling of :meth:`~object.__del__` methods is notoriously "
"implementation specific, since it depends on internal details of the "
"interpreter's garbage collector implementation."
msgstr ""
"然而,眾所周知,對 :meth:`~object.__del__` 方法的處理是特地實作的,因為它依賴"
"於直譯器的垃圾回收器實作的內部細節。"

#: ../../library/weakref.rst:564
msgid ""
"A more robust alternative can be to define a finalizer which only references "
"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 ""
"Defined like this, our finalizer only receives a reference to the details it "
"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 ""
"The other advantage of weakref based finalizers is that they can be used to "
"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 ""
Expand All @@ -660,3 +721,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: ...`` 也不保證清理會發生。"
Loading