Skip to content
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

Translate reference/import.py #1005

Draft
wants to merge 2 commits into
base: 3.13
Choose a base branch
from
Draft
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
78 changes: 70 additions & 8 deletions reference/import.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 11:11+0800\n"
"PO-Revision-Date: 2024-11-06 14:55+0800\n"
"PO-Revision-Date: 2024-12-23 15:33+0800\n"
"Last-Translator: Ken Cheng <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand Down Expand Up @@ -1007,7 +1007,7 @@ msgstr ""

#: ../../reference/import.rst:546
msgid "__path__ attributes on modules"
msgstr ""
msgstr "模組上的 __path__ 屬性"

#: ../../reference/import.rst:548
msgid ""
Expand All @@ -1016,6 +1016,9 @@ msgid ""
"submodules will be found. By definition, if a module has a :attr:`!__path__` "
"attribute, it is a :term:`package`."
msgstr ""
":attr:`~module.__path__` 屬性應該是一個(可能為空的)\\ :term:`sequence`,其"
"包含列舉套件子模組位置的字串。根據定義,如果一個模組有 :attr:`!__path__` 屬"
"性,那麼它就是一個 :term:`package`。"

#: ../../reference/import.rst:553
msgid ""
Expand All @@ -1025,13 +1028,18 @@ msgid ""
"during import. However, :attr:`!__path__` is typically much more constrained "
"than :data:`!sys.path`."
msgstr ""
"套件的 :attr:`~module.__path__` 屬性在引入其子套件時被使用。在引入機制中,其"
"功能與 :data:`sys.path` 類似,即提供在引入期間搜尋模組的位置串列。然而,:"
"attr:`!__path__` 通常比 :data:`!sys.path` 更受限制。"

#: ../../reference/import.rst:560
msgid ""
"The same rules used for :data:`sys.path` also apply to a package's :attr:`!"
"__path__`. :data:`sys.path_hooks` (described below) are consulted when "
"traversing a package's :attr:`!__path__`."
msgstr ""
":data:`sys.path` 適用的規則同樣也適用於套件的 :attr:`!__path__`。 :data:`sys."
"path_hooks` 會在遍歷套件的 :attr:`!__path__` 時被參考(於後文詳述)。"

#: ../../reference/import.rst:564
msgid ""
Expand All @@ -1042,17 +1050,23 @@ msgid ""
"containing only :attr:`!__path__` manipulation code; the import machinery "
"automatically sets :attr:`!__path__` correctly for the namespace package."
msgstr ""
"套件的 ``__init__.py`` 檔案可以設定或修改套件的 :attr:`~module.__path__` 屬"
"性,這通常是 :pep:`420` 之前實作命名空間套件的方式。隨著 :pep:`420` 的採用,"
"命名空間套件不再需要提供僅包含 :attr:`!__path__` 操作程式碼的 ``__init__."
"py`` 檔案;引入機制會自動為命名空間套件正確地設定 :attr:`!__path__`。"

#: ../../reference/import.rst:573
msgid "Module reprs"
msgstr ""
msgstr "模組的 reprs"

#: ../../reference/import.rst:575
msgid ""
"By default, all modules have a usable repr, however depending on the "
"attributes set above, and in the module's spec, you can more explicitly "
"control the repr of module objects."
msgstr ""
"預設情況下,所有模組都有可用的 repr,然而,根據上述設定及模組規格中的屬性,你"
"可以更明確地控制模組物件的 repr。"

#: ../../reference/import.rst:579
msgid ""
Expand All @@ -1063,44 +1077,54 @@ msgid ""
"__file__``, and ``module.__loader__`` as input into the repr, with defaults "
"for whatever information is missing."
msgstr ""
"如果模組具有規格(\\ ``__spec__``\\ ),引入機制將嘗試從規格中產生 repr。如果"
"失敗或沒有規格,引入系統將使用模組上可用的資訊製作一個預設的 repr。它會嘗試使"
"用 ``module.__name__``、``module.__file__`` 和 ``module.__loader__`` 作為 "
"repr 的輸入,並為缺少的資訊提供預設值。"

#: ../../reference/import.rst:586
msgid "Here are the exact rules used:"
msgstr ""
msgstr "以下是具體的使用規則:"

#: ../../reference/import.rst:588
msgid ""
"If the module has a ``__spec__`` attribute, the information in the spec is "
"used to generate the repr. The \"name\", \"loader\", \"origin\", and "
"\"has_location\" attributes are consulted."
msgstr ""
"如果模組具有 ``__spec__`` 屬性,則使用規格中的資訊產生 repr。會參考 "
"\"name\"、\"loader\"、\"origin\" 和 \"has_location\" 屬性。"

#: ../../reference/import.rst:592
msgid ""
"If the module has a ``__file__`` attribute, this is used as part of the "
"module's repr."
msgstr ""
msgstr "如果模組具有 ``__file__`` 屬性,則會將其作為模組 repr 的一部分。"

#: ../../reference/import.rst:595
msgid ""
"If the module has no ``__file__`` but does have a ``__loader__`` that is not "
"``None``, then the loader's repr is used as part of the module's repr."
msgstr ""
"如果模組沒有 ``__file__`` 但有一個不為 ``None`` 的 ``__loader__`` ,則會將載"
"入器的 repr 作為模組 repr 的一部分。"

#: ../../reference/import.rst:598
msgid "Otherwise, just use the module's ``__name__`` in the repr."
msgstr ""
msgstr "否則,在 repr 中只使用模組的 ``__name__``。"

#: ../../reference/import.rst:600
msgid ""
"Use of :meth:`!module_repr`, having been deprecated since Python 3.4, was "
"removed in Python 3.12 and is no longer called during the resolution of a "
"module's repr."
msgstr ""
":meth:`!module_repr` 自 Python 3.4 起被棄用,並在 Python 3.12 中移除,且不會"
"在解析模組的 repr 時被呼叫。"

#: ../../reference/import.rst:608
msgid "Cached bytecode invalidation"
msgstr ""
msgstr "被快取的位元組碼的無效化"

#: ../../reference/import.rst:610
msgid ""
Expand All @@ -1111,6 +1135,10 @@ msgid ""
"cache file by checking the stored metadata in the cache file against the "
"source's metadata."
msgstr ""
"在 Python 從 ``.pyc`` 檔案載入被快取的位元組碼之前,會檢查該快取是否與來源的 "
"``.py`` 檔案保持同步。預設情況下,Python 透過在寫入快取檔案時儲存來源檔案的最"
"後修改時間戳和大小來完成此操作。在執行時,引入系統會透過將快取檔案中儲存的元"
"資料 (metadata) 與來源檔案的元資料進行比對來驗證快取檔案。"

#: ../../reference/import.rst:617
msgid ""
Expand All @@ -1125,16 +1153,25 @@ msgid ""
"Hash-based ``.pyc`` files validation behavior may be overridden with the :"
"option:`--check-hash-based-pycs` flag."
msgstr ""
"Python 還支援「基於雜湊」的快取檔案,這些檔案儲存來源檔案內容的雜湊值,而不是"
"其元資料。基於雜湊的 ``.pyc`` 檔案有兩種變體:需檢查和不需要檢查的。對於需檢"
"查的基於雜湊的 ``.pyc`` 檔案,Python 透過對來源檔案進行雜湊並將結果與快取檔案"
"中的雜湊進行比較來驗證快取檔案。如果發現需檢查的基於雜湊的快取檔案無效,"
"Python 會重新產生並寫入新的需檢查的基於雜湊的快取檔案。對於不需要檢查的基於雜"
"湊的 ``.pyc`` 檔案,只要檔案存在,Python 就假設快取檔案是有效的。可以使用 :"
"option:`--check-hash-based-pycs` 旗標覆蓋基於雜湊的 ``.pyc`` 檔案的驗證行為。"

#: ../../reference/import.rst:628
msgid ""
"Added hash-based ``.pyc`` files. Previously, Python only supported timestamp-"
"based invalidation of bytecode caches."
msgstr ""
"新增了基於雜湊的 ``.pyc`` 檔案。此前,Python 只支援基於時間戳的位元組碼快取無"
"效化。"

#: ../../reference/import.rst:634
msgid "The Path Based Finder"
msgstr ""
msgstr "基於路徑的尋檢器"

#: ../../reference/import.rst:639
msgid ""
Expand All @@ -1144,13 +1181,19 @@ msgid ""
"contains a list of :term:`path entries <path entry>`. Each path entry names "
"a location to search for modules."
msgstr ""
"如前所述,Python 附帶了幾個預設的元路徑尋檢器。其中之一稱為 :term:`path "
"based finder`\\ (\\ :class:`~importlib.machinery.PathFinder`\\ ),它搜尋 :"
"term:`import path`,該路徑包含一個 :term:`路徑條目 <path entry>` 的串列。每個"
"路徑條目都指定了一個用於搜尋模組的位置。"

#: ../../reference/import.rst:645
msgid ""
"The path based finder itself doesn't know how to import anything. Instead, "
"it traverses the individual path entries, associating each of them with a "
"path entry finder that knows how to handle that particular kind of path."
msgstr ""
"基於路徑的尋檢器本身並不知道如何引入任何東西。相反,它遍歷各個路徑條目,並將"
"每個路徑條目與一個知道如何處理該特定路徑類型的路徑條目尋檢器關聯起來。"

#: ../../reference/import.rst:649
msgid ""
Expand All @@ -1162,13 +1205,20 @@ msgid ""
"also handle loading all of these file types (other than shared libraries) "
"from zipfiles."
msgstr ""
"預設的一組路徑條目尋檢器實作了在檔案系統中尋找模組的所有語意,包括處理特殊檔"
"案類型,例如 Python 原始程式碼檔案(``.py`` 檔案)、Python 位元組程式碼檔案"
"(``.pyc`` 檔案)以及共享函式庫(例如 ``.so`` 檔案)。當標準函式庫中的 :mod:"
"`zipimport` 模組支援時,預設的路徑條目尋檢器也能處理從壓縮檔案中載入這些檔案"
"類型(共享函式庫除外)。"

#: ../../reference/import.rst:656
msgid ""
"Path entries need not be limited to file system locations. They can refer "
"to URLs, database queries, or any other location that can be specified as a "
"string."
msgstr ""
"路徑條目不必侷限於檔案系統位置。它們可以參照 URL、資料庫查詢或任何可以作為字"
"串指定的位置。"

#: ../../reference/import.rst:660
msgid ""
Expand All @@ -1180,6 +1230,10 @@ msgid ""
"protocol described below, which was then used to get a loader for the module "
"from the web."
msgstr ""
"基於路徑的尋檢器提供了額外的掛鉤和協定,讓你可以擴展和自定可搜尋的路徑條目類"
"型。例如,如果你希望支援將路徑條目作為網路 URLs,你可以撰寫一個實作 HTTP 語意"
"的掛鉤,用於在網路上尋找模組。這個掛鉤(一個可呼叫物件)會回傳一個支援下述協"
"定的 :term:`path entry finder` ,該尋檢器隨後用於從網路中獲取模組的載入器。"

#: ../../reference/import.rst:668
msgid ""
Expand All @@ -1191,6 +1245,11 @@ msgid ""
"In particular, meta path finders operate at the beginning of the import "
"process, as keyed off the :data:`sys.meta_path` traversal."
msgstr ""
"提醒一句:本節與前一節都使用了 *尋檢器* 這個術語,並透過使用術語 :term:`meta "
"path finder` 和 :term:`path entry finder` 來區分它們。這兩種類型的尋檢器非常"
"相似,支援類似的協定,並在引入過程中以類似的方式運作,但請記住,它們之間有些"
"微的差異。特別是,元路徑尋檢器在引入過程的一開始運作,並通過 :data:`sys."
"meta_path` 的遍歷關閉 (key off)。"

#: ../../reference/import.rst:676
msgid ""
Expand All @@ -1199,6 +1258,9 @@ msgid ""
"removed from :data:`sys.meta_path`, none of the path entry finder semantics "
"would be invoked."
msgstr ""
"相比之下,路徑條目尋檢器在某種意義上是基於路徑的尋檢器的一個實作細節。事實"
"上,如果基於路徑的尋檢器從 :data:`sys.meta_path` 中移除,路徑條目尋檢器的任何"
"語意都不會被調用。"

#: ../../reference/import.rst:683
msgid "Path entry finders"
Expand Down