Skip to content

Commit 2efe0c8

Browse files
authored
Merge pull request #986 from ken71301/translate-reference-import
Translate `reference/import.po`
2 parents 82742b5 + 24165e5 commit 2efe0c8

File tree

1 file changed

+112
-10
lines changed

1 file changed

+112
-10
lines changed

reference/import.po

+112-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ msgstr ""
77
"Project-Id-Version: Python 3.13\n"
88
"Report-Msgid-Bugs-To: \n"
99
"POT-Creation-Date: 2024-09-03 11:11+0800\n"
10-
"PO-Revision-Date: 2024-10-07 21:14+0800\n"
11-
"Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\n"
10+
"PO-Revision-Date: 2024-11-06 14:55+0800\n"
11+
"Last-Translator: Ken Cheng <ken71301@gmail.com>\n"
1212
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1313
"tw)\n"
1414
"Language: zh_TW\n"
@@ -599,14 +599,16 @@ msgstr ""
599599

600600
#: ../../reference/import.rst:342
601601
msgid "Loading"
602-
msgstr ""
602+
msgstr "載入"
603603

604604
#: ../../reference/import.rst:344
605605
msgid ""
606606
"If and when a module spec is found, the import machinery will use it (and "
607607
"the loader it contains) when loading the module. Here is an approximation "
608608
"of what happens during the loading portion of import::"
609609
msgstr ""
610+
"如果找到模組規格,引入機制會在載入模組時使用該規格(以及它包含的載入器)。以"
611+
"下是引入過程中載入部分的大致情況: ::"
610612

611613
#: ../../reference/import.rst:348
612614
msgid ""
@@ -639,16 +641,45 @@ msgid ""
639641
" raise\n"
640642
"return sys.modules[spec.name]"
641643
msgstr ""
644+
"module = None\n"
645+
"if spec.loader is not None and hasattr(spec.loader, 'create_module'):\n"
646+
" # 這裡假設載入器上也會定義 'exec_module'\n"
647+
" module = spec.loader.create_module(spec)\n"
648+
"if module is None:\n"
649+
" module = ModuleType(spec.name)\n"
650+
"# 與引入相關的模組屬性會在此處設定:\n"
651+
"_init_module_attrs(spec, module)\n"
652+
"\n"
653+
"if spec.loader is None:\n"
654+
" # 不支援\n"
655+
" raise ImportError\n"
656+
"if spec.origin is None and spec.submodule_search_locations is not None:\n"
657+
" # 命名空間套件\n"
658+
" sys.modules[spec.name] = module\n"
659+
"elif not hasattr(spec.loader, 'exec_module'):\n"
660+
" module = spec.loader.load_module(spec.name)\n"
661+
"else:\n"
662+
" sys.modules[spec.name] = module\n"
663+
" try:\n"
664+
" spec.loader.exec_module(module)\n"
665+
" except BaseException:\n"
666+
" try:\n"
667+
" del sys.modules[spec.name]\n"
668+
" except KeyError:\n"
669+
" pass\n"
670+
" raise\n"
671+
"return sys.modules[spec.name]"
642672

643673
#: ../../reference/import.rst:377
644674
msgid "Note the following details:"
645-
msgstr ""
675+
msgstr "請注意下列細節:"
646676

647677
#: ../../reference/import.rst:379
648678
msgid ""
649679
"If there is an existing module object with the given name in :data:`sys."
650680
"modules`, import will have already returned it."
651681
msgstr ""
682+
"如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,引入會已回傳該物件。"
652683

653684
#: ../../reference/import.rst:382
654685
msgid ""
@@ -658,6 +689,9 @@ msgid ""
658689
"prevents unbounded recursion in the worst case and multiple loading in the "
659690
"best."
660691
msgstr ""
692+
"在載入器執行模組程式碼之前,模組將已存在於 :data:`sys.modules` 中。這一點至關"
693+
"重要,因為模組程式碼可能會(直接或間接)引入自己;事先將其增加到 :data:`sys."
694+
"modules` 可以預防類似無限遞迴以及多次重覆載入等情形。"
661695

662696
#: ../../reference/import.rst:388
663697
msgid ""
@@ -667,6 +701,10 @@ msgid ""
667701
"effect, must remain in the cache. This contrasts with reloading where even "
668702
"the failing module is left in :data:`sys.modules`."
669703
msgstr ""
704+
"如果載入失敗,只有載入失敗的模組會從 :data:`sys.modules` 中刪除。任何已存在"
705+
"於 :data:`sys.modules` 快取中的模組,以及任何在載入失敗前成功載入的模組,都必"
706+
"須保留在快取中。此情形與重新載入不同,在重新載入時,即使載入失敗的模組也會保"
707+
"留在 :data:`sys.modules` 中。"
670708

671709
#: ../../reference/import.rst:394
672710
msgid ""
@@ -675,30 +713,39 @@ msgid ""
675713
"code example above), as summarized in a :ref:`later section <import-mod-"
676714
"attrs>`."
677715
msgstr ""
716+
"模組建立後、在執行之前,引入機制會設置與引入相關的模組屬性(在上面的偽程式碼"
717+
"範例中為 \"_init_module_attrs\"),具體內容在\\ :ref:`之後的段落<import-mod-"
718+
"attrs>`\\ 會總結。"
678719

679720
#: ../../reference/import.rst:399
680721
msgid ""
681722
"Module execution is the key moment of loading in which the module's "
682723
"namespace gets populated. Execution is entirely delegated to the loader, "
683724
"which gets to decide what gets populated and how."
684725
msgstr ""
726+
"模組執行是載入過程中的關鍵時刻,此時模組的命名空間會被新增名稱。執行過程完全"
727+
"交由載入器處理,由其決定如何新增以及新增什麼。"
685728

686729
#: ../../reference/import.rst:403
687730
msgid ""
688731
"The module created during loading and passed to exec_module() may not be the "
689732
"one returned at the end of import [#fnlo]_."
690733
msgstr ""
734+
"在載入過程中建立並傳遞給 exec_module() 的模組,可能不會是引入結束時回傳的模"
735+
"組 [#fnlo]_。"
691736

692737
#: ../../reference/import.rst:406
693738
msgid ""
694739
"The import system has taken over the boilerplate responsibilities of "
695740
"loaders. These were previously performed by the :meth:`importlib.abc.Loader."
696741
"load_module` method."
697742
msgstr ""
743+
"引入系統已接管載入器的模板 (boilerplate) 責任。之前是由 :meth:`importlib.abc."
744+
"Loader.load_module` 方法執行的。"
698745

699746
#: ../../reference/import.rst:412
700747
msgid "Loaders"
701-
msgstr ""
748+
msgstr "載入器"
702749

703750
#: ../../reference/import.rst:414
704751
msgid ""
@@ -707,31 +754,41 @@ msgid ""
707754
"method with a single argument, the module object to execute. Any value "
708755
"returned from :meth:`~importlib.abc.Loader.exec_module` is ignored."
709756
msgstr ""
757+
"模組載入器提供了載入的關鍵功能:模組執行。引入機制會以單一引數(即要執行的模"
758+
"組物件)呼叫 :meth:`importlib.abc.Loader.exec_module` 方法。任何從 :meth:"
759+
"`~importlib.abc.Loader.exec_module` 回傳的值都會被忽略。"
710760

711761
#: ../../reference/import.rst:419
712762
msgid "Loaders must satisfy the following requirements:"
713-
msgstr ""
763+
msgstr "載入器必須滿足以下要求:"
714764

715765
#: ../../reference/import.rst:421
716766
msgid ""
717767
"If the module is a Python module (as opposed to a built-in module or a "
718768
"dynamically loaded extension), the loader should execute the module's code "
719769
"in the module's global name space (``module.__dict__``)."
720770
msgstr ""
771+
"如果模組是 Python 模組(而非內建模組或動態載入的擴充),載入器應在模組的全域"
772+
"命名空間 (``module.__dict__``\\ ) 中執行該模組的程式碼。"
721773

722774
#: ../../reference/import.rst:425
723775
msgid ""
724776
"If the loader cannot execute the module, it should raise an :exc:"
725777
"`ImportError`, although any other exception raised during :meth:`~importlib."
726778
"abc.Loader.exec_module` will be propagated."
727779
msgstr ""
780+
"如果載入器無法執行該模組,應引發 :exc:`ImportError`。不過,在 :meth:"
781+
"`~importlib.abc.Loader.exec_module` 中引發的任何其他例外也會被傳播。"
728782

729783
#: ../../reference/import.rst:429
730784
msgid ""
731785
"In many cases, the finder and loader can be the same object; in such cases "
732786
"the :meth:`~importlib.abc.MetaPathFinder.find_spec` method would just return "
733787
"a spec with the loader set to ``self``."
734788
msgstr ""
789+
"在許多情況下,尋檢器和載入器可以是同一個物件;在這種情況下,:meth:"
790+
"`~importlib.abc.MetaPathFinder.find_spec` 方法只需回傳一個載入器設為 "
791+
"``self`` 的規格即可。"
735792

736793
#: ../../reference/import.rst:433
737794
msgid ""
@@ -742,17 +799,23 @@ msgid ""
742799
"the module object. If the method returns ``None``, the import machinery "
743800
"will create the new module itself."
744801
msgstr ""
802+
"模組載入器可以選擇透過實作 :meth:`~importlib.abc.Loader.create_module` 方法,"
803+
"在載入過程中建立模組物件。該方法接受一個引數,即模組規格,並回傳在載入過程中"
804+
"要使用的新的模組物件。``create_module()`` 不需要在模組物件上設定任何屬性。如"
805+
"果該方法回傳 ``None``,引入機制將自行建立新的模組。"
745806

746807
#: ../../reference/import.rst:440
747808
msgid "The :meth:`~importlib.abc.Loader.create_module` method of loaders."
748-
msgstr ""
809+
msgstr "載入器的 :meth:`~importlib.abc.Loader.create_module` 方法。"
749810

750811
#: ../../reference/import.rst:443
751812
msgid ""
752813
"The :meth:`~importlib.abc.Loader.load_module` method was replaced by :meth:"
753814
"`~importlib.abc.Loader.exec_module` and the import machinery assumed all the "
754815
"boilerplate responsibilities of loading."
755816
msgstr ""
817+
":meth:`~importlib.abc.Loader.load_module` 方法已被 :meth:`~importlib.abc."
818+
"Loader.exec_module` 取代,引入機制已承擔所有載入的模板責任。"
756819

757820
#: ../../reference/import.rst:448
758821
msgid ""
@@ -761,13 +824,18 @@ msgid ""
761824
"also implement ``exec_module()``. However, ``load_module()`` has been "
762825
"deprecated and loaders should implement ``exec_module()`` instead."
763826
msgstr ""
827+
"為了與現有的載入器相容,引入機制會在載入器未實作 ``exec_module()`` 且存在 "
828+
"``load_module()`` 方法時使用該方法。然而,``load_module()`` 已被棄用,載入器"
829+
"應改為實作 ``exec_module()``。"
764830

765831
#: ../../reference/import.rst:453
766832
msgid ""
767833
"The ``load_module()`` method must implement all the boilerplate loading "
768834
"functionality described above in addition to executing the module. All the "
769835
"same constraints apply, with some additional clarification:"
770836
msgstr ""
837+
"``load_module()`` 方法除了執行模組外,還必須實作上述全部的模板載入功能。所有"
838+
"相同的限制依然適用,並且還有一些額外的說明:"
771839

772840
#: ../../reference/import.rst:457
773841
msgid ""
@@ -777,35 +845,48 @@ msgid ""
777845
"exist in :data:`sys.modules`, the loader must create a new module object and "
778846
"add it to :data:`sys.modules`."
779847
msgstr ""
848+
"如果 :data:`sys.modules` 中已存在具有給定名稱的模組物件,載入器必須使用該模組"
849+
"(否則 :func:`importlib.reload` 將無法正常運作)。如果命名模組不存在於 :data:"
850+
"`sys.modules` 中,載入器必須建立一個新的模組物件並將其新增至 :data:`sys."
851+
"modules`。"
780852

781853
#: ../../reference/import.rst:463
782854
msgid ""
783855
"The module *must* exist in :data:`sys.modules` before the loader executes "
784856
"the module code, to prevent unbounded recursion or multiple loading."
785857
msgstr ""
858+
"在載入器執行模組程式碼之前,該模組\\ *必須*\\ 已存在於 :data:`sys.modules` "
859+
"中,以防止無限遞迴或多次載入。"
786860

787861
#: ../../reference/import.rst:467
788862
msgid ""
789863
"If loading fails, the loader must remove any modules it has inserted into :"
790864
"data:`sys.modules`, but it must remove **only** the failing module(s), and "
791865
"only if the loader itself has loaded the module(s) explicitly."
792866
msgstr ""
867+
"如果載入失敗,載入器必須移除已經插入到 :data:`sys.modules` 中的任何模組,但"
868+
"\\ **只能**\\ 移除失敗的模組(們),且僅在載入器本身明確載入這些模組時才需移"
869+
"除。"
793870

794871
#: ../../reference/import.rst:472
795872
msgid ""
796873
"A :exc:`DeprecationWarning` is raised when ``exec_module()`` is defined but "
797874
"``create_module()`` is not."
798875
msgstr ""
876+
"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
877+
"`DeprecationWarning`。"
799878

800879
#: ../../reference/import.rst:476
801880
msgid ""
802881
"An :exc:`ImportError` is raised when ``exec_module()`` is defined but "
803882
"``create_module()`` is not."
804883
msgstr ""
884+
"當 ``exec_module()`` 已定義但未定義 ``create_module()`` 時,將引發 :exc:"
885+
"`ImportError`。"
805886

806887
#: ../../reference/import.rst:480
807888
msgid "Use of ``load_module()`` will raise :exc:`ImportWarning`."
808-
msgstr ""
889+
msgstr "使用 ``load_module()`` 將引發 :exc:`ImportWarning`。"
809890

810891
#: ../../reference/import.rst:484
811892
msgid "Submodules"
@@ -820,6 +901,11 @@ msgid ""
820901
"``spam.foo``, ``spam`` will have an attribute ``foo`` which is bound to the "
821902
"submodule. Let's say you have the following directory structure::"
822903
msgstr ""
904+
"當使用任何機制(例如 ``importlib`` APIs、``import`` 或 ``import-from`` 陳述"
905+
"式,或內建的 ``__import__()``\\ )載入子模組時,會將子模組物件繫結到父模組的"
906+
"命名空間中。例如,如果套件 ``spam`` 有一個子模組 ``foo``,則在引入 ``spam."
907+
"foo`` 之後,``spam`` 將擁有一個名為 ``foo`` 的屬性,該屬性繫結到子模組。我們"
908+
"假設你有以下的目錄結構: ::"
823909

824910
#: ../../reference/import.rst:493
825911
msgid ""
@@ -833,7 +919,7 @@ msgstr ""
833919

834920
#: ../../reference/import.rst:497
835921
msgid "and ``spam/__init__.py`` has the following line in it::"
836-
msgstr ""
922+
msgstr "並且 ``spam/__init__.py`` 中包含以下程式碼: ::"
837923

838924
#: ../../reference/import.rst:499
839925
msgid "from .foo import Foo"
@@ -844,6 +930,7 @@ msgid ""
844930
"then executing the following puts name bindings for ``foo`` and ``Foo`` in "
845931
"the ``spam`` module::"
846932
msgstr ""
933+
"那麼執行以下程式碼會將 ``foo`` 和 ``Foo`` 的名稱繫結到 ``spam`` 模組中: ::"
847934

848935
#: ../../reference/import.rst:504
849936
msgid ""
@@ -867,10 +954,14 @@ msgid ""
867954
"foo']`` (as you would after the above import), the latter must appear as the "
868955
"``foo`` attribute of the former."
869956
msgstr ""
957+
"鑑於 Python 相似的名稱繫結規則,這可能看起來有些出人意料,但這實際上是引入系"
958+
"統的一個基本特性。不變的是如果你擁有 ``sys.modules['spam']`` 和 ``sys."
959+
"modules['spam.foo']``(就像上述引入後那樣),那麼後者必須作為前者的 ``foo`` "
960+
"屬性出現。"
870961

871962
#: ../../reference/import.rst:519
872963
msgid "Module specs"
873-
msgstr ""
964+
msgstr "模組規格"
874965

875966
#: ../../reference/import.rst:521
876967
msgid ""
@@ -879,6 +970,9 @@ msgid ""
879970
"modules. The purpose of a module's spec is to encapsulate this import-"
880971
"related information on a per-module basis."
881972
msgstr ""
973+
"引入機制在引入過程中使用有關每個模組的各種資訊,尤其是在載入之前。大多數資訊"
974+
"對所有模組來說都是通用的。模組規格的目的是以每個模組為基礎封裝這些與引入相關"
975+
"的資訊。"
882976

883977
#: ../../reference/import.rst:526
884978
msgid ""
@@ -888,6 +982,9 @@ msgid ""
888982
"machinery to perform the boilerplate operations of loading, whereas without "
889983
"a module spec the loader had that responsibility."
890984
msgstr ""
985+
"在引入過程中使用規格允許在引入系統的各個組件之間傳遞狀態,例如在建立模組規格"
986+
"的尋檢器和執行該規格的載入器之間傳遞。最重要的是,這允許引入機制執行載入的模"
987+
"板操作,而在沒有模組規格的情況下,這些操作則是載入器的責任。"
891988

892989
#: ../../reference/import.rst:532
893990
msgid ""
@@ -896,12 +993,17 @@ msgid ""
896993
"interpreter startup <programs>`. The one exception is ``__main__``, where :"
897994
"attr:`!__spec__` is :ref:`set to None in some cases <main_spec>`."
898995
msgstr ""
996+
"模組的規格以 :attr:`module.__spec__` 的形式公開。適當地設定 :attr:`!"
997+
"__spec__` 同樣適用於\\ :ref:`在直譯器啟動期間初始化的模組 <programs>`。唯一的"
998+
"例外是 ``__main__``,其中 :attr:`!__spec__` 會\\ :ref:`在某些情況下被設定成 "
999+
"None <main_spec>`。"
8991000

9001001
#: ../../reference/import.rst:538
9011002
msgid ""
9021003
"See :class:`~importlib.machinery.ModuleSpec` for details on the contents of "
9031004
"the module spec."
9041005
msgstr ""
1006+
"有關模組規格內容的詳細資訊,請參閱 :class:`~importlib.machinery.ModuleSpec`。"
9051007

9061008
#: ../../reference/import.rst:546
9071009
msgid "__path__ attributes on modules"

0 commit comments

Comments
 (0)