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.po #983

Open
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Open
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
118 changes: 111 additions & 7 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: 2018-05-23 16:17+0000\n"
"PO-Revision-Date: 2024-10-03 12:34+0800\n"
"Last-Translator: Adrian Liaw <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All @@ -16,6 +16,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.5\n"

#: ../../reference/import.rst:6
msgid "The import system"
Expand All @@ -29,6 +30,10 @@ msgid ""
"way. Functions such as :func:`importlib.import_module` and built-in :func:"
"`__import__` can also be used to invoke the import machinery."
msgstr ""
"一個 :term:`module` 中的 Python 程式碼通過 :term:`importing` 的過程來存取另一"
"個模組中的程式碼。:keyword:`import` 陳述式是調用 (invoke) 引入機制最常見的方"
"法,但這不是唯一的方法。函式如 :func:`importlib.import_module` 以及內建函式 :"
"func:`__import__` 也可以用來調用引入機制。"

#: ../../reference/import.rst:16
msgid ""
Expand All @@ -41,6 +46,11 @@ msgid ""
"keyword:`!import` statement for the exact details of that name binding "
"operation."
msgstr ""
":keyword:`import` 陳述式結合了兩個操作:首先搜尋指定的模組,然後將搜尋結果繫"
"結到本地作用域中的一個名稱。:keyword:`!import` 陳述式的搜尋操作被定義為一個"
"對 :func:`__import__` 函式的呼叫,並帶有相應的引數。:func:`__import__` 的回傳"
"值用於執行 :keyword:`!import` 陳述式的名稱繫結操作。有關名稱繫結操作的詳細資"
"訊,請參見 :keyword:`!import` 陳述式。"

#: ../../reference/import.rst:25
msgid ""
Expand All @@ -50,6 +60,10 @@ msgid ""
"(including :data:`sys.modules`), only the :keyword:`import` statement "
"performs a name binding operation."
msgstr ""
"直接呼叫 :func:`__import__` 只會執行模組搜尋操作,以及在找到時執行模組的建立"
"操作。雖然某些副作用可能會發生,例如引入父套件 (parent package),以及更新各種"
"快取(包括 :data:`sys.modules`),但只有 :keyword:`import` 陳述式會執行名稱繫"
"結操作。"

#: ../../reference/import.rst:31
msgid ""
Expand All @@ -58,6 +72,9 @@ msgid ""
"system (such as :func:`importlib.import_module`) may choose to bypass :func:"
"`__import__` and use their own solutions to implement import semantics."
msgstr ""
"當執行 :keyword:`import` 陳述式時,會呼叫內建的 :func:`__import__` 函式。其他"
"調用引入系統的機制(如 :func:`importlib.import_module`)可以選擇略過 :func:"
"`__import__`,並使用它們自己的解決方案來實作引入語意。"

#: ../../reference/import.rst:36
msgid ""
Expand All @@ -68,6 +85,10 @@ msgid ""
"machinery is invoked. These strategies can be modified and extended by "
"using various hooks described in the sections below."
msgstr ""
"當模組首次被引入時,Python 會搜尋該模組,若找到則會建立一個模組物件 "
"[#fnmo]_,並對其進行初始化。如果找不到指定的模組,則會引發 :exc:"
"`ModuleNotFoundError`。當引入機制被調用時,Python 會實作各種策略來搜尋指定的"
"模組。這些策略可以透過使用以下章節描述的各種 hook(掛鉤)來修改和擴展。"

#: ../../reference/import.rst:43
msgid ""
Expand All @@ -76,6 +97,9 @@ msgid ""
"import system is exposed through :data:`sys.meta_path`. In addition, native "
"namespace package support has been implemented (see :pep:`420`)."
msgstr ""
"引入系統已被更新,以完全實作 :pep:`302` 的第二階段。不再有隱式引入機制——完整"
"的引入系統已透過 :data:`sys.meta_path` 公開。此外,原生命名空間套件支援(請參"
"閱 :pep:`420`)也已被實作。"

#: ../../reference/import.rst:51
msgid ":mod:`importlib`"
Expand All @@ -89,6 +113,9 @@ msgid ""
"import machinery. Refer to the :mod:`importlib` library documentation for "
"additional detail."
msgstr ""
":mod:`importlib` 模組提供了豐富的 API 來與引入系統互動。例如,:func:"
"`importlib.import_module` 提供了一個比內建的 :func:`__import__` 更推薦且更簡"
"單的 API 來調用引入機制。更多詳細資訊請參閱 :mod:`importlib` 函式庫文件。"

#: ../../reference/import.rst:62
msgid "Packages"
Expand All @@ -101,6 +128,9 @@ msgid ""
"else. To help organize modules and provide a naming hierarchy, Python has a "
"concept of :term:`packages <package>`."
msgstr ""
"Python 只有一種類型的模組物件,且所有模組,無論其是使用 Python、C 還是其他語"
"言實作,都是這種類型。為了幫助組織模組並提供命名階層,Python 導入了 :term:`套"
"件 <package>` 的概念。"

#: ../../reference/import.rst:72
msgid ""
Expand All @@ -112,6 +142,10 @@ msgid ""
"hierarchically, and packages may themselves contain subpackages, as well as "
"regular modules."
msgstr ""
"你可以將套件視為檔案系統中的目錄,模組則是目錄中的檔案,但不要過於字面地理解"
"這個比喻,因為套件和模組不一定來自檔案系統。為了方便解釋,我們將使用這個目錄"
"和檔案的比喻。就像檔案系統目錄一樣,套件是分層組織的,套件本身可以包含子套件"
"以及一般模組。"

#: ../../reference/import.rst:80
msgid ""
Expand All @@ -120,6 +154,8 @@ msgid ""
"of module. Specifically, any module that contains a ``__path__`` attribute "
"is considered a package."
msgstr ""
"請記住,所有的套件都是模組,但並非所有模組都是套件。換句話說,套件只是一種特"
"殊的模組。具體來說,任何包含 ``__path__`` 屬性的模組都被視為套件。"

#: ../../reference/import.rst:85
msgid ""
Expand All @@ -129,10 +165,14 @@ msgid ""
"subpackage called :mod:`email.mime` and a module within that subpackage "
"called :mod:`email.mime.text`."
msgstr ""
"所有模組都有一個名稱。子套件的名稱與其父套件名稱之間用一個點來分隔,類似於 "
"Python 的標準屬性存取語法。因此,你可能會有一個名為 :mod:`email` 的套件,該套"
"件又有一個名為 :mod:`email.mime` 的子套件,並且該子套件中有一個名為 :mod:"
"`email.mime.text` 的模組。"

#: ../../reference/import.rst:93
msgid "Regular packages"
msgstr ""
msgstr "一般套件"

#: ../../reference/import.rst:98
msgid ""
Expand All @@ -146,12 +186,20 @@ msgid ""
"same Python code that any other module can contain, and Python will add some "
"additional attributes to the module when it is imported."
msgstr ""
"Python 定義了兩種類型的套件,:term:`一般套件 <regular package>`\\ 和\\ :term:"
"`命名空間套件 <namespace package>`。一般套件是 Python 3.2 及更早版本中存在的"
"傳統套件。一般套件通常實作成一個包含 ``__init__.py`` 檔案的目錄。當引入一般套"
"件時,該 ``__init__.py`` 檔案會被隱式執行,其定義的物件會繫結到該套件的命名空"
"間中的名稱。``__init__.py`` 檔案可以包含與任何其他模組相同的 Python 代碼,並"
"且 Python 會在引入時為該模組增加一些額外的屬性。"

#: ../../reference/import.rst:108
msgid ""
"For example, the following file system layout defines a top level ``parent`` "
"package with three subpackages::"
msgstr ""
"例如,以下檔案系統布置定義了一個頂層的 ``parent`` 套件,該套件包含三個子套"
"件: ::"

#: ../../reference/import.rst:111
msgid ""
Expand Down Expand Up @@ -180,10 +228,13 @@ msgid ""
"``parent.three`` will execute ``parent/two/__init__.py`` and ``parent/three/"
"__init__.py`` respectively."
msgstr ""
"引入 ``parent.one`` 將隱式執行 ``parent/__init__.py`` 和 ``parent/one/"
"__init__.py``。隨後引入 ``parent.two`` 或 ``parent.three`` 將分別執行 "
"``parent/two/__init__.py`` 和 ``parent/three/__init__.py``。"

#: ../../reference/import.rst:127
msgid "Namespace packages"
msgstr ""
msgstr "命名空間套件"

#: ../../reference/import.rst:133
msgid ""
Expand All @@ -195,6 +246,10 @@ msgid ""
"objects on the file system; they may be virtual modules that have no "
"concrete representation."
msgstr ""
"命名空間套件是由不同的\\ :term:`部分 <portion>` 組成的,每個部分都為父套件提"
"供一個子套件。這些部分可以位於檔案系統上的不同位置。部分可能也存在於壓縮檔案"
"中、網路上,或 Python 在引入時搜尋的任何其他地方。命名空間套件不一定直接對應"
"於檔案系統中的對象;它們可能是沒有具體表示的虛擬模組。"

#: ../../reference/import.rst:141
msgid ""
Expand All @@ -204,6 +259,9 @@ msgid ""
"that package if the path of their parent package (or :data:`sys.path` for a "
"top level package) changes."
msgstr ""
"命名空間套件的 ``__path__`` 屬性不使用普通的串列。它們使用自定義的可疊代型"
"別,當父套件的路徑(或頂層套件的 :data:`sys.path`)發生變化時,會在下一次引入"
"嘗試時自動執行新一輪的套件部分搜尋。"

#: ../../reference/import.rst:147
msgid ""
Expand All @@ -214,14 +272,19 @@ msgid ""
"create a namespace package for the top-level ``parent`` package whenever it "
"or one of its subpackages is imported."
msgstr ""
"在命名空間套件中,不存在 ``parent/__init__.py`` 檔案。實際上,在引入搜尋過程"
"中可能會找到多個 ``parent`` 目錄,每個目錄由不同的部分提供。因此,``parent/"
"one`` 可能與 ``parent/two`` 不會實際位於一起。在這種情況下,每當引入頂層 "
"``parent`` 套件或其子套件之一時,Python 會為頂層 ``parent`` 套件建立一個命名"
"空間套件。"

#: ../../reference/import.rst:154
msgid "See also :pep:`420` for the namespace package specification."
msgstr ""
msgstr "有關命名空間套件的規範,請參見 :pep:`420`。"

#: ../../reference/import.rst:158
msgid "Searching"
msgstr ""
msgstr "搜尋"

#: ../../reference/import.rst:160
msgid ""
Expand All @@ -232,6 +295,10 @@ msgid ""
"parameters to the :func:`importlib.import_module` or :func:`__import__` "
"functions."
msgstr ""
"在開始搜尋之前,Python 需要被引入模組(或套件,但在本討論中,兩者的區別無關緊"
"要)的完整\\ :term:`限定名稱 <qualified name>`。此名稱可能來自 :keyword:"
"`import` 陳述式的各種引數,或來自 :func:`importlib.import_module` 或 :func:"
"`__import__` 函式的參數。"

#: ../../reference/import.rst:166
msgid ""
Expand All @@ -241,10 +308,14 @@ msgid ""
"baz``. If any of the intermediate imports fail, a :exc:`ModuleNotFoundError` "
"is raised."
msgstr ""
"此名稱將在引入搜尋的各個階段中使用,並且它可能是指向子模組的點分隔路徑,例如 "
"``foo.bar.baz``。在這種情況下,Python 會首先嘗試引入 ``foo``,然後是 ``foo."
"bar``,最後是 ``foo.bar.baz``。如果任何中間引入失敗,則會引發 :exc:"
"`ModuleNotFoundError`。"

#: ../../reference/import.rst:173
msgid "The module cache"
msgstr ""
msgstr "模組快取"

#: ../../reference/import.rst:178
msgid ""
Expand All @@ -255,6 +326,10 @@ msgid ""
"and ``foo.bar.baz``. Each key will have as its value the corresponding "
"module object."
msgstr ""
"在引入搜尋過程中首先檢查的地方是 :data:`sys.modules`。此對映用作所有先前引入"
"過的模組的快取,包括中間路徑。因此,如果 ``foo.bar.baz`` 之前已被引入,:data:"
"`sys.modules` 將包含 ``foo``、``foo.bar`` 和 ``foo.bar.baz`` 的條目。每個鍵的"
"值都是相應的模組物件。"

#: ../../reference/import.rst:185
msgid ""
Expand All @@ -264,6 +339,9 @@ msgid ""
"`ModuleNotFoundError` is raised. If the module name is missing, Python will "
"continue searching for the module."
msgstr ""
"在引入過程中,會在 :data:`sys.modules` 中查找模組名稱,如果存在,則相關的值為"
"滿足此引入的模組,此引入過程即完成。然而,如果值是 ``None``,則會引發 :exc:"
"`ModuleNotFoundError`。如果模組名稱不存在,Python 會繼續搜尋該模組。"

#: ../../reference/import.rst:191
msgid ""
Expand All @@ -274,6 +352,10 @@ msgid ""
"to ``None``, forcing the next import of the module to result in a :exc:"
"`ModuleNotFoundError`."
msgstr ""
":data:`sys.modules` 是可寫入的。刪除一個鍵可能不會銷毀相關聯的模組(因為其他"
"模組可能持有對它的參照),但會使指定的模組的快取條目失效,導致 Python 在下一"
"次引入該模組時重新搜尋。也可以將鍵賦值為 ``None``,這會強制下一次引入該模組時"
"引發 :exc:`ModuleNotFoundError`。"

#: ../../reference/import.rst:198
msgid ""
Expand All @@ -283,10 +365,14 @@ msgid ""
"reload` will reuse the *same* module object, and simply reinitialise the "
"module contents by rerunning the module's code."
msgstr ""
"但請注意,如果你保留了對模組物件的參照,並在 :data:`sys.modules` 中使其快取條"
"目失效,然後重新引入指定的模組,這兩個模組物件將\\ *不會*\\ 相同。相比之下,:"
"func:`importlib.reload` 會重用\\ *相同的*\\ 模組物件,並通過重新執行模組的程"
"式碼來簡單地重新初始化模組內容。"

#: ../../reference/import.rst:208
msgid "Finders and loaders"
msgstr ""
msgstr "尋檢器與載入器"

#: ../../reference/import.rst:215
msgid ""
Expand All @@ -299,6 +385,11 @@ msgid ""
"they return themselves when they find that they can load the requested "
"module."
msgstr ""
"如果在 :data:`sys.modules` 中找不到指定的模組,則會調用 Python 的引入協定來尋"
"找並載入該模組。這個協定由兩個概念性物件組成,:term:`尋檢器 <finder>` 和\\ :"
"term:`載入器 <loader>`。尋檢器的任務是使用其已知的策略來確定是否能找到命名模"
"組。實作這兩個介面的物件稱為\\ :term:`引入器 <importer>` ——當它們發現可以載入"
"所請求的模組時,會回傳它們自己。"

#: ../../reference/import.rst:223
msgid ""
Expand All @@ -309,12 +400,17 @@ msgid ""
"system paths or zip files. It can also be extended to search for any "
"locatable resource, such as those identified by URLs."
msgstr ""
"Python 包含多個預設的尋檢器和引入器。第一個尋檢器知道如何定位內建模組,第二個"
"尋檢器知道如何定位凍結模組。第三個預設尋檢器會在 :term:`import path` 中搜尋模"
"組。:term:`import path` 是一個位置的列表,這些位置可能是檔案系統路徑或壓縮檔"
"案,也可以擴展以搜尋任何可定位的資源,例如由 URL 識別的資源。"

#: ../../reference/import.rst:230
msgid ""
"The import machinery is extensible, so new finders can be added to extend "
"the range and scope of module searching."
msgstr ""
"引入機制是可擴展的,因此可以增加新的尋檢器來擴展模組搜尋的範圍和作用域。"

#: ../../reference/import.rst:233
msgid ""
Expand All @@ -323,20 +419,28 @@ msgid ""
"related information, which the import machinery then uses when loading the "
"module."
msgstr ""
"尋檢器實際上不會載入模組。如果它們能找到指定的模組,它們會回傳一個\\ :dfn:`模"
"組規格`,這是一個模組的引入相關資訊的封裝,引入機制會在載入模組時使用這些資"
"訊。"

#: ../../reference/import.rst:237
msgid ""
"The following sections describe the protocol for finders and loaders in more "
"detail, including how you can create and register new ones to extend the "
"import machinery."
msgstr ""
"以下各節將更詳細地描述尋檢器和載入器的協定,包括如何建立和註冊新的尋檢器和載"
"入器來擴展引入機制。"

#: ../../reference/import.rst:241
msgid ""
"In previous versions of Python, finders returned :term:`loaders <loader>` "
"directly, whereas now they return module specs which *contain* loaders. "
"Loaders are still used during import but have fewer responsibilities."
msgstr ""
"Python 在之前的版本中,尋檢器會直接回傳\\ :term:`載入器 <loader>`,而現在它們"
"回傳的是\\ *包含*\\ 載入器的模組規格。載入器仍在引入過程中使用,但其責任減少"
"了。"

#: ../../reference/import.rst:247
msgid "Import hooks"
Expand Down