From 6662303569d097ae3d5feb1507df23d2d6bce54f Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sun, 15 Jul 2018 17:21:44 +0800 Subject: [PATCH 01/12] Add the translation of Into, 9.1, 9.2, 9.3.1 --- tutorial/classes.po | 130 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 15 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 6cad24d4b60..436d944add9 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-05-23 16:18+0000\n" +"PO-Revision-Date: 2018-07-15 17:19+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -17,10 +17,12 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Poedit 2.0.9\n" +"X-Poedit-Bookmarks: 0,22,44,66,88,-1,-1,-1,-1,-1\n" #: ../../tutorial/classes.rst:5 msgid "Classes" -msgstr "" +msgstr "類別" #: ../../tutorial/classes.rst:7 msgid "" @@ -30,6 +32,9 @@ msgid "" "attributes attached to it for maintaining its state. Class instances can " "also have methods (defined by its class) for modifying its state." msgstr "" +"類別提供了一種結合資料與功能的方法,新增一個類別將會新增一個物件的 *型別* ," +"並且允許建立該型別新的 *實例* 。每一個類別實例可以擁有一些維持該實例狀態的屬" +"性。類別實例也可以擁有一些用於修改該實例狀態的方法 (由其所屬類別定義)。" #: ../../tutorial/classes.rst:13 msgid "" @@ -44,6 +49,13 @@ msgid "" "nature of Python: they are created at runtime, and can be modified further " "after creation." msgstr "" +"與其他程式語言相比,Python 的類別機制為類別新增了最少的格式跟語意。他混合了 C" +"++ 和 Modula-3 的類別機制。Python 的類別提供了標準物件導向程式設計 (Object " +"Oriented Programming) 的特色:類別繼承允許繼承多個基礎類別 (Base Class) 、一" +"個衍伸類別 (Derived Class) 可以覆寫(override) 任何其基礎類別的方法,並且方" +"法可以用相同的名稱呼叫其基礎類別的方法。物件可以包含任意數量的不同資料。如同" +"模組一樣,類別也具有 Python 的動態特性:他們在執行時期被建造,並且可以在建造" +"之後被修改。" #: ../../tutorial/classes.rst:23 msgid "" @@ -59,6 +71,13 @@ msgid "" "(arithmetic operators, subscripting etc.) can be redefined for class " "instances." msgstr "" +"以 C++ 的術語來說,類別成員(包含資料成員)通常都是 *公開* 的(除了以下的內容" +"\\ :ref:`tut-private`\\ ),而所有的成員函式都是 *虛擬* 的。如同在 Modula-3 " +"中一樣,Python 並沒有在物件方法裡參照物件成員的簡寫:被宣告的方法函數明確地以" +"第一個參數代表物件,而此參數會在呼叫時隱性地被提供。如同在 Smalltak 中,類別" +"都是物件。這樣為引入及重命名提供了語意。不像在 C++ 和 Modula-3中,內建的型態" +"可以作為基礎類別被用於使用者的延伸。另外,如同在 C++中,多數內建有著特別格式" +"的運算子(算術運算子、下標等)可以為類別實例被重新定義。" #: ../../tutorial/classes.rst:34 msgid "" @@ -67,10 +86,13 @@ msgid "" "since its object-oriented semantics are closer to those of Python than C++, " "but I expect that few readers have heard of it.)" msgstr "" +"(由於缺乏普遍能接受的用語來討論類別,我偶而會使用 Smalltalk 和 C++ 的術語。" +"我會使用 Modula-3 的術語,因為他比 C++ 更接近 Python 的物件導向語意, 但我預期" +"比較少的讀者會聽過他。)" #: ../../tutorial/classes.rst:43 msgid "A Word About Names and Objects" -msgstr "" +msgstr "關於名稱與物件的一段話" #: ../../tutorial/classes.rst:45 msgid "" @@ -87,10 +109,18 @@ msgid "" "the caller will see the change --- this eliminates the need for two " "different argument passing mechanisms as in Pascal." msgstr "" +"物件有 identity,並且有多個名稱(在多個作用域 (scopes) )可以被綁定到同樣的物" +"件。這在其他語言中被稱為別名 (aliasing) 。初次接觸 Python 通常不會理解這件" +"事,在處理不可動的基本型別(數值、字串、元組)時可以安全地忽略這件事。然而," +"別名可能會在含有可變物件(如串列、字典、和大多數其他的型別)的 Python 程式碼" +"語意中有令人驚訝的效果。這通常有利於程式,因為別名在某些方面表現得像指標。舉" +"例來說,實作時只有指標被傳遞,因此傳遞物件是便宜的;假如函式修改了一個作為參" +"數傳遞的物件,呼叫函式者能夠見到這些改變 --- 這消除了在 Pascal 中需要兩種不同" +"的參數傳遞機制。" #: ../../tutorial/classes.rst:61 msgid "Python Scopes and Namespaces" -msgstr "" +msgstr "Python 作用域 (Scopes) 及命名空間 (Namespaces)" #: ../../tutorial/classes.rst:63 msgid "" @@ -100,10 +130,13 @@ msgid "" "understand what's going on. Incidentally, knowledge about this subject is " "useful for any advanced Python programmer." msgstr "" +"在介紹類別之前,我需要先告訴您一些關於 Python 作用域的規則。類別定義用命名空" +"間發揮了一些巧妙的技巧,你需要了解作用域和命名空間的運作才能完整理解正在發生" +"的事情。順面一題,有關這次主題的知識是有益於任何進階的 Python 程式員。" #: ../../tutorial/classes.rst:69 msgid "Let's begin with some definitions." -msgstr "" +msgstr "讓我們從一些定義開始。" #: ../../tutorial/classes.rst:71 msgid "" @@ -119,6 +152,13 @@ msgid "" "may both define a function ``maximize`` without confusion --- users of the " "modules must prefix it with the module name." msgstr "" +"*命名空間* 是從名稱到物件的映射。大部分的命名空間現在都是以 Python 的字典實" +"作,但通常不會以任何方式顯示(除了性能),且它可能會在未來改變。命名空間的例" +"子有:內建函式的集合(包含如 :func:`abs` 函式,和內建的例外名稱);模組中的全" +"域名稱;和在函式調用中的區域名稱。某種意義上,物件中的屬性集合也會形成一個命" +"名空間。關於命名空間的重要一點是,不同命名空間中的名稱之間絕對沒有關係;舉例" +"來說,兩個不一樣的模組可以定義 ``maximize`` 的函式而不會混淆 --- 模組的用戶必" +"須在它前面加上模塊名稱。" #: ../../tutorial/classes.rst:82 msgid "" @@ -130,6 +170,11 @@ msgid "" "happens to be a straightforward mapping between the module's attributes and " "the global names defined in the module: they share the same namespace! [#]_" msgstr "" +"順帶一提,我使用*屬性*這個字統稱點後面的任何名稱 --- 如,表達式中的 ``z." +"real``,``real`` 是物件 ``z`` 的一個屬性。嚴格地來說,模組中名稱的參照都是屬" +"性參照:在表達式 ``modname.funcname`` 中,``modname`` 是模組物件而 " +"``funcname`` 是它的屬性。在這種情況下,模組的屬性和模組中定義的全域名稱碰巧有" +"一個直接的映射:他們共享了同樣的命名空間![#]_" #: ../../tutorial/classes.rst:90 msgid "" @@ -139,6 +184,10 @@ msgid "" "the :keyword:`del` statement. For example, ``del modname.the_answer`` will " "remove the attribute :attr:`the_answer` from the object named by ``modname``." msgstr "" +"屬性可以是唯讀的或可寫的。 在後一種情況下,對屬性的賦值是可能的。模組屬性是可" +"寫的: 你可以寫 ``modname.the_answer = 42``。可寫屬性也可以用 :keyword:`del` " +"語句刪除。 例如,``del modname.the_answer`` 將從名稱 ``modname`` 的物件中刪除" +"屬性 :attr:`the_answer`。" #: ../../tutorial/classes.rst:96 msgid "" @@ -152,6 +201,12 @@ msgid "" "`__main__`, so they have their own global namespace. (The built-in names " "actually also live in a module; this is called :mod:`builtins`.)" msgstr "" +"命名空間在不同的時刻被建立並且會有不同的壽命。當 Python 直譯器起動時,有著內" +"建名稱的命名空間將會被建立,並且用遠不會被刪除。當模組的定義被讀入時,模組全" +"域的命名空間會被建立;一般情況下,模組的命名空間也會持續到直譯器離開。經由腳" +"本檔案或是互動式從直譯器高階調用而執行的語句被視為模組的一部份,稱為 :mod:" +"`__main__`,因此他們具有他們自身的全域命名空間。(內建名稱事實上也存在於模組" +"當中,被稱為 :mod:`builtins`。)" #: ../../tutorial/classes.rst:106 msgid "" @@ -161,6 +216,9 @@ msgid "" "describe what actually happens.) Of course, recursive invocations each have " "their own local namespace." msgstr "" +"函數的區域命名空間是在呼叫函數時創建的,當函數返回或引發未在函數中處理的異常" +"時,將會被刪除。(實際上, 忘記是描述實際發生的事情的更好方法。) 當然, 每個" +"遞迴呼叫都有自己的本地命名空間。" #: ../../tutorial/classes.rst:112 msgid "" @@ -168,6 +226,8 @@ msgid "" "directly accessible. \"Directly accessible\" here means that an unqualified " "reference to a name attempts to find the name in the namespace." msgstr "" +"*作用域* 是 Python 程式中可以直接存取命名空間的文本區域。這裡的“直接存取”意味" +"著對名稱的非限定參照可以在命名空間內嘗試找到其對應的名稱。" #: ../../tutorial/classes.rst:116 msgid "" @@ -175,26 +235,30 @@ msgid "" "time during execution, there are at least three nested scopes whose " "namespaces are directly accessible:" msgstr "" +"儘管作用域是靜態確定的,但他們是動態地被使用的。在執行期間內的任何時候,至少" +"有三個巢狀的作用域其命名空間是可以被直接存取的:" #: ../../tutorial/classes.rst:120 msgid "the innermost scope, which is searched first, contains the local names" -msgstr "" +msgstr "最先搜索的最內層作用域,包含區域名稱" #: ../../tutorial/classes.rst:121 msgid "" "the scopes of any enclosing functions, which are searched starting with the " "nearest enclosing scope, contains non-local, but also non-global names" msgstr "" +"從最近的封閉作用域開始搜尋的任何封閉函數之作用域,包含非區域名稱也包括非全域" +"名稱" #: ../../tutorial/classes.rst:123 msgid "the next-to-last scope contains the current module's global names" -msgstr "" +msgstr "倒數第二個作用域包含當前模組的全域名稱" #: ../../tutorial/classes.rst:124 msgid "" "the outermost scope (searched last) is the namespace containing built-in " "names" -msgstr "" +msgstr "最外面的作用域(最後搜尋)是包含內建名稱的命名空間" #: ../../tutorial/classes.rst:126 msgid "" @@ -206,6 +270,10 @@ msgid "" "*new* local variable in the innermost scope, leaving the identically named " "outer variable unchanged)." msgstr "" +"如果名稱宣告為全域,則所有參照和賦值將直接轉到包含模組全域名稱的中間作用域。" +"要重新綁定最內層作用範圍以外找到的變數,可以使用:keyword:`nonlocal`語句;如" +"果沒有聲明為非本地變數,那些變數是唯讀的(嘗試寫入這樣的變數只會在最內層的作" +"用域內創建一個 *new* 區域變數,保持同名的外部變數不變)。" #: ../../tutorial/classes.rst:133 msgid "" @@ -214,6 +282,9 @@ msgid "" "namespace as the global scope: the module's namespace. Class definitions " "place yet another namespace in the local scope." msgstr "" +"通常,區域作用域參照到(文本)當前函式的區域名稱。在函式外部,區域作用域參照" +"與全域作用域相同的命名空間:模組的命名空間。類別定義在區域作用域中放置另一個" +"命名空間。" #: ../../tutorial/classes.rst:138 msgid "" @@ -225,6 +296,10 @@ msgid "" "at \"compile\" time, so don't rely on dynamic name resolution! (In fact, " "local variables are already determined statically.)" msgstr "" +"重要的是要意識到作用域是以文本方式確定的:模組中定義函式的全域作用域便是模組" +"的命名空間,無論從何處或透過呼叫什麼函式別名。另一方面,名稱的實際搜尋是在執" +"行時動態完成的 --- 但是,語言定義在“編譯”時朝著靜態名稱解析發展,所以不要依賴" +"於動態名稱解析! (事實上,局部變數已經靜態地確定。)" #: ../../tutorial/classes.rst:146 msgid "" @@ -237,6 +312,11 @@ msgid "" "`import` statements and function definitions bind the module or function " "name in the local scope." msgstr "" +"一個特殊的 Python 怪癖是 -- 假如沒有使用 :keyword:`global` 語句 -- 名稱的賦值" +"都會指向最內層作用域。賦值不會複製資料 --- 它們只會綁定名稱至物件。刪除也是同" +"樣的:``del x`` 語句自區域作用域的命名空間移除 ``x`` 的綁定。事實上,引入新名" +"稱的所有的運算都使用區域作用域:特別是在區域作用域的 :keyword:`import` 語句和" +"綁定模組或函式名稱的函式定義。" #: ../../tutorial/classes.rst:154 msgid "" @@ -245,10 +325,13 @@ msgid "" "`nonlocal` statement indicates that particular variables live in an " "enclosing scope and should be rebound there." msgstr "" +":keyword:`global` 語句可以用來表示特定變數生活在全域作用域內, 應該在那裡重新" +"綁定;:keyword:`nonlocal` 語句表示特定變數生活在封閉作用域內, 應該在那裡重新" +"綁定。" #: ../../tutorial/classes.rst:162 msgid "Scopes and Namespaces Example" -msgstr "" +msgstr "作用域和命名空間的範例" #: ../../tutorial/classes.rst:164 msgid "" @@ -256,10 +339,12 @@ msgid "" "namespaces, and how :keyword:`global` and :keyword:`nonlocal` affect " "variable binding::" msgstr "" +"這是一個範例, 演示如何參照不同的作用域和命名空間, 以及 :keyword:`global` " +"和 :keyword:`global` 如何影響變數綁定::" #: ../../tutorial/classes.rst:191 msgid "The output of the example code is:" -msgstr "" +msgstr "範例程式碼的輸出是:" #: ../../tutorial/classes.rst:200 msgid "" @@ -268,30 +353,33 @@ msgid "" "*scope_test*\\'s binding of *spam*, and the :keyword:`global` assignment " "changed the module-level binding." msgstr "" +"請注意, *local* 賦值(預設值) 沒有更改 *scope_test* 的 *spam* 綁定。 :" +"keyword:`nonlocal` 賦值已更改 *scope_test* 中 *spam* 的綁定 , 和 :keyword:" +"`global` 賦值更改了模組層級綁定。" #: ../../tutorial/classes.rst:205 msgid "" "You can also see that there was no previous binding for *spam* before the :" "keyword:`global` assignment." -msgstr "" +msgstr "您還可以看到, 在 :keyword:`global` 賦值之前沒有 *spam* 的綁定。" #: ../../tutorial/classes.rst:212 msgid "A First Look at Classes" -msgstr "" +msgstr "初看類別" #: ../../tutorial/classes.rst:214 msgid "" "Classes introduce a little bit of new syntax, three new object types, and " "some new semantics." -msgstr "" +msgstr "類別採用一些新的格式,三個新的物件型別,以及一些新的語意。" #: ../../tutorial/classes.rst:221 msgid "Class Definition Syntax" -msgstr "" +msgstr "類別定義格式" #: ../../tutorial/classes.rst:223 msgid "The simplest form of class definition looks like this::" -msgstr "" +msgstr "類別定義最簡單的形式如下:" #: ../../tutorial/classes.rst:232 msgid "" @@ -300,6 +388,8 @@ msgid "" "a class definition in a branch of an :keyword:`if` statement, or inside a " "function.)" msgstr "" +"類別定義,如同函式定義(:keyword:`def` 語句)必須在他們有作用前先執行。(你可" +"以想像放置類別定義在一個 :keyword:`if` 語句的分支,或在函式裡。)" #: ../../tutorial/classes.rst:236 msgid "" @@ -309,6 +399,9 @@ msgid "" "normally have a peculiar form of argument list, dictated by the calling " "conventions for methods --- again, this is explained later." msgstr "" +"在實踐中,類別定義內的語句通常會是函式定義,但其他語句也是允許的,有時很有用 " +"--- 我們等等會回到這裡。類別中的函式定義通常會有特別的參數排列形式,由方法" +"(method)的呼叫慣例決定 -- 再一次地,這將會在等等被解釋。" #: ../../tutorial/classes.rst:242 msgid "" @@ -317,6 +410,9 @@ msgid "" "new namespace. In particular, function definitions bind the name of the new " "function here." msgstr "" +"當進入類別定義,一個新的命名空間將會被建立,並且作為區域作用域 --- 因此,所有" +"區域變數的賦值將進入這個新的命名空間。特別的是,函式定義在這裡綁定該函式名" +"稱。" #: ../../tutorial/classes.rst:247 msgid "" @@ -328,6 +424,10 @@ msgid "" "here to the class name given in the class definition header (:class:" "`ClassName` in the example)." msgstr "" +"正常離開類別定義時(結束時),會創建一個 *類別物件*。這基本上是類別定義建立的" +"命名空間內容的包裝器(wrapper);我們將在下一節中更加了解類別物件。原本的區域" +"作用域(在輸入類別定義之前已生效的作用域)會恢復,在此類別物件會綁定到類別定" +"義標頭中給出的類別名(在範例中為 :class:`ClassName`)。" #: ../../tutorial/classes.rst:259 msgid "Class Objects" From 34b88d4976ab6a55d43e4cffa4792342e8310fef Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sun, 15 Jul 2018 21:34:35 +0800 Subject: [PATCH 02/12] =?UTF-8?q?Change=20term=20'=E6=A0=BC=E5=BC=8F'=20in?= =?UTF-8?q?to=20'=E8=AA=9E=E6=B3=95'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorial/classes.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 436d944add9..e32f7e825e0 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-07-15 17:19+0800\n" +"PO-Revision-Date: 2018-07-15 21:33+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -49,7 +49,7 @@ msgid "" "nature of Python: they are created at runtime, and can be modified further " "after creation." msgstr "" -"與其他程式語言相比,Python 的類別機制為類別新增了最少的格式跟語意。他混合了 C" +"與其他程式語言相比,Python 的類別機制為類別新增了最少的語法跟語意。他混合了 C" "++ 和 Modula-3 的類別機制。Python 的類別提供了標準物件導向程式設計 (Object " "Oriented Programming) 的特色:類別繼承允許繼承多個基礎類別 (Base Class) 、一" "個衍伸類別 (Derived Class) 可以覆寫(override) 任何其基礎類別的方法,並且方" @@ -76,7 +76,7 @@ msgstr "" "中一樣,Python 並沒有在物件方法裡參照物件成員的簡寫:被宣告的方法函數明確地以" "第一個參數代表物件,而此參數會在呼叫時隱性地被提供。如同在 Smalltak 中,類別" "都是物件。這樣為引入及重命名提供了語意。不像在 C++ 和 Modula-3中,內建的型態" -"可以作為基礎類別被用於使用者的延伸。另外,如同在 C++中,多數內建有著特別格式" +"可以作為基礎類別被用於使用者的延伸。另外,如同在 C++中,多數內建有著特別語法" "的運算子(算術運算子、下標等)可以為類別實例被重新定義。" #: ../../tutorial/classes.rst:34 @@ -371,11 +371,11 @@ msgstr "初看類別" msgid "" "Classes introduce a little bit of new syntax, three new object types, and " "some new semantics." -msgstr "類別採用一些新的格式,三個新的物件型別,以及一些新的語意。" +msgstr "類別採用一些新的語法,三個新的物件型別,以及一些新的語意。" #: ../../tutorial/classes.rst:221 msgid "Class Definition Syntax" -msgstr "類別定義格式" +msgstr "類別定義語法" #: ../../tutorial/classes.rst:223 msgid "The simplest form of class definition looks like this::" From ae56d94f31b659edc627c8fd048d9835b0ec4914 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Mon, 16 Jul 2018 02:01:06 +0800 Subject: [PATCH 03/12] Add translation of 9.3.2 --- tutorial/classes.po | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index e32f7e825e0..22e1eb86304 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-07-15 21:33+0800\n" +"PO-Revision-Date: 2018-07-16 01:59+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" "X-Generator: Poedit 2.0.9\n" -"X-Poedit-Bookmarks: 0,22,44,66,88,-1,-1,-1,-1,-1\n" +"X-Poedit-Bookmarks: 0,26,52,77,102,-1,-1,-1,-1,-1\n" #: ../../tutorial/classes.rst:5 msgid "Classes" @@ -431,13 +431,13 @@ msgstr "" #: ../../tutorial/classes.rst:259 msgid "Class Objects" -msgstr "" +msgstr "類別物件" #: ../../tutorial/classes.rst:261 msgid "" "Class objects support two kinds of operations: attribute references and " "instantiation." -msgstr "" +msgstr "類別物件支援兩種運算:屬性參照和實例化。" #: ../../tutorial/classes.rst:264 msgid "" @@ -446,6 +446,9 @@ msgid "" "that were in the class's namespace when the class object was created. So, " "if the class definition looked like this::" msgstr "" +"*屬性參照*使用 Python 中所有屬性參照使用的標準語法:``obj.name``。有效的屬性" +"名稱是創建類別物件時類別命名空間中所有的名稱。所以,如果類別定義看起來像這" +"樣::" #: ../../tutorial/classes.rst:276 msgid "" @@ -455,6 +458,10 @@ msgid "" "assignment. :attr:`__doc__` is also a valid attribute, returning the " "docstring belonging to the class: ``\"A simple example class\"``." msgstr "" +"那麼 ``MyClass.i`` 和 ``MyClass.f`` 都是有效的屬性參照,會分別回傳一個整數和" +"一個函式物件。類別屬性也可以被指派(assign),所以您可以透過賦值改變 " +"``MyClass.i`` 的值。:attr:`__doc__`也是一個有效的屬性,會回傳屬於該類別的文件" +"字串(docstring):``\"A simple example class\"``。" #: ../../tutorial/classes.rst:282 msgid "" @@ -462,12 +469,14 @@ msgid "" "object is a parameterless function that returns a new instance of the class. " "For example (assuming the above class)::" msgstr "" +"類別 *實例化* 使用了函式標記(function notation)。只是假裝類別物建是沒有參數" +"並回傳一個新的類別實例的函式。例如(假設是上述的類別)::" #: ../../tutorial/classes.rst:288 msgid "" "creates a new *instance* of the class and assigns this object to the local " "variable ``x``." -msgstr "" +msgstr "建立類別的新 *實例 *, 並將此物件指派給區域變數 ``x``。" #: ../../tutorial/classes.rst:291 msgid "" @@ -476,6 +485,9 @@ msgid "" "specific initial state. Therefore a class may define a special method named :" "meth:`__init__`, like this::" msgstr "" +"實例化運算(“呼叫”一個類別物件)建立一個空的物件。許多類別喜歡建立一個有著自" +"訂特定初始狀態實例的物件。因此,類別可以定義一個名為 :meth:`__init__` 的特別" +"方法,如下::" #: ../../tutorial/classes.rst:299 msgid "" @@ -484,6 +496,8 @@ msgid "" "instance. So in this example, a new, initialized instance can be obtained " "by::" msgstr "" +"當類別定義了 :meth:`__init__` 方法,類別實例化會自動為新建的類別實例調用 :" +"meth:`__init__`。所以在這個範例中,一個新的、初始化的實例可以如此獲得::" #: ../../tutorial/classes.rst:305 msgid "" @@ -491,6 +505,8 @@ msgid "" "flexibility. In that case, arguments given to the class instantiation " "operator are passed on to :meth:`__init__`. For example, ::" msgstr "" +"當然, :meth:`__init__` 方法可能為了更多的彈性而有參數。在這種情況下,給類別" +"實例化運算子的參數會被傳遞給 :meth:`__init__`。例如,::" #: ../../tutorial/classes.rst:322 msgid "Instance Objects" From 5008221bd3563b43051ee0096115a866a76c1e57 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Wed, 18 Jul 2018 00:53:19 +0800 Subject: [PATCH 04/12] Add translation of 9.3.3 --- tutorial/classes.po | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 22e1eb86304..ad82176e2ab 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-07-16 01:59+0800\n" +"PO-Revision-Date: 2018-07-18 00:52+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -73,7 +73,7 @@ msgid "" msgstr "" "以 C++ 的術語來說,類別成員(包含資料成員)通常都是 *公開* 的(除了以下的內容" "\\ :ref:`tut-private`\\ ),而所有的成員函式都是 *虛擬* 的。如同在 Modula-3 " -"中一樣,Python 並沒有在物件方法裡參照物件成員的簡寫:被宣告的方法函數明確地以" +"中一樣,Python 並沒有在物件方法裡參照物件成員的簡寫:被宣告的方法函式明確地以" "第一個參數代表物件,而此參數會在呼叫時隱性地被提供。如同在 Smalltak 中,類別" "都是物件。這樣為引入及重命名提供了語意。不像在 C++ 和 Modula-3中,內建的型態" "可以作為基礎類別被用於使用者的延伸。另外,如同在 C++中,多數內建有著特別語法" @@ -87,8 +87,8 @@ msgid "" "but I expect that few readers have heard of it.)" msgstr "" "(由於缺乏普遍能接受的用語來討論類別,我偶而會使用 Smalltalk 和 C++ 的術語。" -"我會使用 Modula-3 的術語,因為他比 C++ 更接近 Python 的物件導向語意, 但我預期" -"比較少的讀者會聽過他。)" +"我會使用 Modula-3 的術語,因為他比 C++ 更接近 Python 的物件導向語意, 但我預" +"期比較少的讀者會聽過他。)" #: ../../tutorial/classes.rst:43 msgid "A Word About Names and Objects" @@ -216,7 +216,7 @@ msgid "" "describe what actually happens.) Of course, recursive invocations each have " "their own local namespace." msgstr "" -"函數的區域命名空間是在呼叫函數時創建的,當函數返回或引發未在函數中處理的異常" +"函式的區域命名空間是在呼叫函式時創建的,當函式返回或引發未在函式中處理的異常" "時,將會被刪除。(實際上, 忘記是描述實際發生的事情的更好方法。) 當然, 每個" "遞迴呼叫都有自己的本地命名空間。" @@ -247,7 +247,7 @@ msgid "" "the scopes of any enclosing functions, which are searched starting with the " "nearest enclosing scope, contains non-local, but also non-global names" msgstr "" -"從最近的封閉作用域開始搜尋的任何封閉函數之作用域,包含非區域名稱也包括非全域" +"從最近的封閉作用域開始搜尋的任何封閉函式之作用域,包含非區域名稱也包括非全域" "名稱" #: ../../tutorial/classes.rst:123 @@ -326,7 +326,7 @@ msgid "" "enclosing scope and should be rebound there." msgstr "" ":keyword:`global` 語句可以用來表示特定變數生活在全域作用域內, 應該在那裡重新" -"綁定;:keyword:`nonlocal` 語句表示特定變數生活在封閉作用域內, 應該在那裡重新" +"綁定;:keyword:`nonlocal` 語句表示特定變數生活在封閉作用域內, 應該在那裡重新" "綁定。" #: ../../tutorial/classes.rst:162 @@ -353,8 +353,8 @@ msgid "" "*scope_test*\\'s binding of *spam*, and the :keyword:`global` assignment " "changed the module-level binding." msgstr "" -"請注意, *local* 賦值(預設值) 沒有更改 *scope_test* 的 *spam* 綁定。 :" -"keyword:`nonlocal` 賦值已更改 *scope_test* 中 *spam* 的綁定 , 和 :keyword:" +"請注意, *local* 賦值(預設值) 沒有更改 *scope_test* 的 *spam* 綁定。 :" +"keyword:`nonlocal` 賦值已更改 *scope_test* 中 *spam* 的綁定 , 和 :keyword:" "`global` 賦值更改了模組層級綁定。" #: ../../tutorial/classes.rst:205 @@ -510,7 +510,7 @@ msgstr "" #: ../../tutorial/classes.rst:322 msgid "Instance Objects" -msgstr "" +msgstr "實例物件" #: ../../tutorial/classes.rst:324 msgid "" @@ -518,6 +518,8 @@ msgid "" "instance objects are attribute references. There are two kinds of valid " "attribute names, data attributes and methods." msgstr "" +"現在, 我們可以如何處理實例物件? 實例物件能理解的唯一運算是屬性參照。 有兩種" +"有效的屬性名,資料屬性和方法。" #: ../../tutorial/classes.rst:328 msgid "" @@ -528,6 +530,10 @@ msgid "" "following piece of code will print the value ``16``, without leaving a " "trace::" msgstr "" +"*資料屬性* 對應 Smalltalk 中的 “實例變數”, 以及 c++ 中的 \"資料成員\"。 資料" +"屬性不需要宣告;和區域變數一樣, 它們在第一次賦值時就會存在。 例如, 如果" +"``x``是 :class:`MyClass`在上述例子中建立的實例, 下面的程式碼將列印值 " +"``16``, 而不留下蹤跡::" #: ../../tutorial/classes.rst:340 msgid "" @@ -539,6 +545,10 @@ msgid "" "exclusively to mean methods of class instance objects, unless explicitly " "stated otherwise.)" msgstr "" +"另一種實例屬性參照是 *方法 *。方法是 \"屬於\" 物件的函式。(在 Python 中, 對" +"類別實例來說術語方法並不是唯一的: 其他物件類型也可以有方法。 例如, 串列物件" +"具有稱為 append、insert、remove、sort 等方法。但是, 在下面的討論中, 我們將" +"只使用術語方法來表示類別實例物件的方法, 除非另有明確說明。)" #: ../../tutorial/classes.rst:349 msgid "" @@ -549,6 +559,10 @@ msgid "" "not, since ``MyClass.i`` is not. But ``x.f`` is not the same thing as " "``MyClass.f`` --- it is a *method object*, not a function object." msgstr "" +"實例物件的有效方法名稱取決於其類別。 根據定義, 作為類別中函式物件的所有屬性" +"都定義其實例的相應方法。 所以在我們的例子中, ``x.f`` 是一個有效的方法參照, " +"因為 ``MyClass.f``是一個函式, 但 ``x.i`` 不是,因為 ``MyClass.i`` 不是。 但 " +"``x.f`` 與 ``MyClass.f`` 是不一樣的---它是一個 *方法物件*, 而不是函式物件。" #: ../../tutorial/classes.rst:360 msgid "Method Objects" From 84d7826a24cacf92caa27b8c2ce00180ba8cb02e Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Fri, 19 Oct 2018 01:32:53 +0800 Subject: [PATCH 05/12] Add translation of section 3.3.4 --- tutorial/classes.po | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index ad82176e2ab..2cfc5a9130e 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-07-18 00:52+0800\n" +"PO-Revision-Date: 2018-10-19 01:31+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\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 2.0.9\n" +"X-Generator: Poedit 2.2\n" "X-Poedit-Bookmarks: 0,26,52,77,102,-1,-1,-1,-1,-1\n" #: ../../tutorial/classes.rst:5 @@ -566,11 +566,11 @@ msgstr "" #: ../../tutorial/classes.rst:360 msgid "Method Objects" -msgstr "" +msgstr "方法物件" #: ../../tutorial/classes.rst:362 msgid "Usually, a method is called right after it is bound::" -msgstr "" +msgstr "通常,一個方法在他被綁定後立即被呼叫::" #: ../../tutorial/classes.rst:366 msgid "" @@ -579,10 +579,13 @@ msgid "" "is a method object, and can be stored away and called at a later time. For " "example::" msgstr "" +"在 :class:`MyClass` 的例子中,這將回傳字串 ``’hello world’``。然而,沒有必要" +"立即呼叫這個方法: ``x.f`` 是一個方法物件,並且可以被儲存一陣子後再被呼叫。舉" +"例來說::" #: ../../tutorial/classes.rst:374 msgid "will continue to print ``hello world`` until the end of time." -msgstr "" +msgstr "將會持續印出 ``hello world`` 直到結束。" #: ../../tutorial/classes.rst:376 msgid "" @@ -593,6 +596,10 @@ msgid "" "argument is called without any --- even if the argument isn't actually " "used..." msgstr "" +"當一個方法被呼叫時究竟會發生什麼?你可能已經注意到 ``x.f()`` 呼叫時沒有放置任" +"何的參數,儘管 :meth:`f` 函式定義指定了一個參數。這個參數發生了什麼事?當一個" +"需要參數的函數被調用而沒有任何東西時,Python肯定會引發異常 --- 即使參數實際上" +"沒有被使用..." #: ../../tutorial/classes.rst:382 msgid "" @@ -604,6 +611,10 @@ msgid "" "that is created by inserting the method's instance object before the first " "argument." msgstr "" +"事實上,你可能已經猜到了答案:方法的特殊之處在於實例物件作為該函數中的第一個" +"參數傳遞。在我們的例子中, ``x.f()`` 此呼叫等同於 ``MyClass.f(x)``。一般來" +"說,呼叫一個有 *n* 個參數的方法等同於呼叫一個對應在第一個參數之前插入一個實例" +"物件的一串參數的函數。" #: ../../tutorial/classes.rst:389 msgid "" @@ -617,6 +628,11 @@ msgid "" "from the instance object and the argument list, and the function object is " "called with this new argument list." msgstr "" +"假如你仍然不了解方法怎麼運作,看一眼實作可能會清楚這件事。當一個不是資料屬性" +"的實例屬性被參照時,物件的類別會被搜尋。假如該名字表示函數物件,亦為一個有效" +"的類別屬性,則一個方法物件會藉由打包(指向)實例物件而被創建並且該函數物件只" +"是在抽象物件中被一起找到:這就是方法物件。當方法物件以一串參數被呼叫,新的一" +"串參數會由實例物件和該串參數建構,而該函數物件會藉由新的一串參數被呼叫。" #: ../../tutorial/classes.rst:403 msgid "Class and Instance Variables" From 521be6807e605cef246060e2b299228e1bc51ed6 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Fri, 19 Oct 2018 01:45:00 +0800 Subject: [PATCH 06/12] Add translation of section 3.3.5 --- tutorial/classes.po | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 2cfc5a9130e..bb424e56031 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-19 01:31+0800\n" +"PO-Revision-Date: 2018-10-19 01:44+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -636,7 +636,7 @@ msgstr "" #: ../../tutorial/classes.rst:403 msgid "Class and Instance Variables" -msgstr "" +msgstr "類別及實例變數" #: ../../tutorial/classes.rst:405 msgid "" @@ -644,6 +644,8 @@ msgid "" "and class variables are for attributes and methods shared by all instances " "of the class::" msgstr "" +"一般來說,實例變數用於每一個實例的獨特資料而類別變數用於屬性和方法會被所有該" +"類別的實例所分享::" #: ../../tutorial/classes.rst:427 msgid "" @@ -653,10 +655,14 @@ msgid "" "not be used as a class variable because just a single list would be shared " "by all *Dog* instances::" msgstr "" +"如同在 :ref:`tut-object`的討論,共享的資料包含 :term:`mutable` 物件可以產生令" +"人驚訝的影響如串列(lists)和字典(dictionaries)。舉例來說,下列程式碼的 " +"*tricks* 串列不應該作為一個類別變數使用,因為他是一個將會被所有 *Dog* 實例共" +"享的串列::" #: ../../tutorial/classes.rst:450 msgid "Correct design of the class should use an instance variable instead::" -msgstr "" +msgstr "正確的類別設計應該使用實例變數::" #: ../../tutorial/classes.rst:474 msgid "Random Remarks" From 72112706bf7ebc4bcd741bb376314deb1fb434af Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Fri, 19 Oct 2018 10:06:01 +0800 Subject: [PATCH 07/12] Add translation of section 9.4 --- tutorial/classes.po | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index bb424e56031..7c7c0112bdf 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-19 01:44+0800\n" +"PO-Revision-Date: 2018-10-19 10:05+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -666,7 +666,7 @@ msgstr "正確的類別設計應該使用實例變數::" #: ../../tutorial/classes.rst:474 msgid "Random Remarks" -msgstr "" +msgstr "隨意的備註" #: ../../tutorial/classes.rst:478 msgid "" @@ -678,6 +678,10 @@ msgid "" "just an underscore), or using verbs for methods and nouns for data " "attributes." msgstr "" +"資料屬性以相同的名稱覆寫方法屬性;為了避免意外的名稱衝突,該衝突將會導致在大" +"的程式中難以發現的錯,明智的方法是使用某種最小化發生衝突的機會之慣例。可能的" +"慣例包含大寫方法名稱,使用小的唯一字串(可能只是下底線)替資料屬性名稱添加前" +"綴,或使用動詞作為方法名稱名詞作為資料屬性名稱。" #: ../../tutorial/classes.rst:485 msgid "" @@ -689,6 +693,10 @@ msgid "" "implementation details and control access to an object if necessary; this " "can be used by extensions to Python written in C.)" msgstr "" +"資料屬性可能被方法及物件的普通用戶(客戶端)所參照。也就是說,類別不可用於實" +"作純粹的抽象資料型態。事實上,在 Python 中沒有任何東西可以有可能使資料隱藏 " +"--- 這全是基於慣例。(另一方面,以 C 實作的 Python 可以完全隱藏實作細節並且必" +"要的話控制物件的存取;這樣可以被以 C 寫的 Python 擴充所使用)" #: ../../tutorial/classes.rst:493 msgid "" @@ -698,6 +706,9 @@ msgid "" "without affecting the validity of the methods, as long as name conflicts are " "avoided --- again, a naming convention can save a lot of headaches here." msgstr "" +"客戶端應該小心使用資料屬性 --- 客戶端可能會通過標記其資料屬性來破壞方法維持的" +"不變性。注意客戶端可能增加資料屬性到實例物件,而不會影響方法的有效性,只要避" +"免名稱衝突即可 --- 再一次提醒,命名慣例可以在這裡節省很多麻煩。" #: ../../tutorial/classes.rst:499 msgid "" @@ -706,6 +717,8 @@ msgid "" "methods: there is no chance of confusing local variables and instance " "variables when glancing through a method." msgstr "" +"在方法中參照資料屬性(或其他方法!)是沒有簡寫的。我發現這實際上增加了方法的" +"可閱讀性:在看方法時,沒有機會混淆區域變數和實例變數。" #: ../../tutorial/classes.rst:504 msgid "" @@ -716,6 +729,10 @@ msgid "" "that a *class browser* program might be written that relies upon such a " "convention." msgstr "" +"通常,方法的第一個參數被叫做 ``self``。這僅僅只是一個慣例:``self`` 這個名字" +"對 Python 來說完全沒有特別的意味。但請注意,如果不遵循慣例,你的程式碼可能對" +"其他 Python 程式員來說可讀性較低,並且也可以想像一個可能依賴於此慣例編寫的 " +"*class browser* 程式。" #: ../../tutorial/classes.rst:510 msgid "" @@ -723,7 +740,7 @@ msgid "" "of that class. It is not necessary that the function definition is " "textually enclosed in the class definition: assigning a function object to a " "local variable in the class is also ok. For example::" -msgstr "" +msgstr "任何是類別屬性的函式物件定義了一個該類別實例的方法。" #: ../../tutorial/classes.rst:527 msgid "" @@ -732,12 +749,15 @@ msgid "" "class:`C` --- ``h`` being exactly equivalent to ``g``. Note that this " "practice usually only serves to confuse the reader of a program." msgstr "" +"現在 ``f``、 ``g`` 和 ``h`` 都是類別 :class:`C` 的屬性,並涉及函數物件,所以" +"他們都是類別 :class:`C` 的實例的方法 --- ``h`` 與 ``g`` 是完全一樣的。請注" +"意,這種做法通常只會使該程式的讀者感到困惑。" #: ../../tutorial/classes.rst:532 msgid "" "Methods may call other methods by using method attributes of the ``self`` " "argument::" -msgstr "" +msgstr "方法可以藉由使用 ``self`` 參數的方法屬性呼叫其他方法::" #: ../../tutorial/classes.rst:546 msgid "" @@ -751,12 +771,20 @@ msgid "" "itself defined in this global scope, and in the next section we'll find some " "good reasons why a method would want to reference its own class." msgstr "" +"方法可以用與一般函數相同的方式參照全域名稱。與方法相關的全域作用域是包含其定" +"義的模組。(類別永遠不會被用作全局範圍。)雖然人們很少有一個在方法中使用全域" +"資料的充分理由,但全域作用域有許多合法使用:一方面,導入全域作用域的函數和模" +"組可以由方法以及在其中定義的函數和類別所使用。通常,包含該方法的類別本身被定" +"義在全域作用域,\n" +"在下一節,我們將找到想要參照自身類別的方法的一些好理由。" #: ../../tutorial/classes.rst:556 msgid "" "Each value is an object, and therefore has a *class* (also called its " "*type*). It is stored as ``object.__class__``." msgstr "" +"每個值都是一個物件,因此有一個 *class*(也可以稱作 *type*)。他被存在 " +"``object.__class__``。" #: ../../tutorial/classes.rst:563 msgid "Inheritance" From 11ab0edf7603517062c60c7543b3f9b6ff223a9e Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sat, 20 Oct 2018 01:02:42 +0800 Subject: [PATCH 08/12] Add translation of section 9.5 Inheritance --- tutorial/classes.po | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 7c7c0112bdf..1ba0af6639d 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-19 10:05+0800\n" +"PO-Revision-Date: 2018-10-20 00:59+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -788,7 +788,7 @@ msgstr "" #: ../../tutorial/classes.rst:563 msgid "Inheritance" -msgstr "" +msgstr "繼承" #: ../../tutorial/classes.rst:565 msgid "" @@ -796,6 +796,8 @@ msgid "" "without supporting inheritance. The syntax for a derived class definition " "looks like this::" msgstr "" +"當然,如果沒有支援繼承,此語言功能就不得稱為 “類別”。定義衍伸類別的語法看起來" +"如下::" #: ../../tutorial/classes.rst:576 msgid "" @@ -804,6 +806,9 @@ msgid "" "expressions are also allowed. This can be useful, for example, when the " "base class is defined in another module::" msgstr "" +"名稱 :class:`BaseClassName` 必須在包含衍伸類別定義的作用域中定義。替代掉基底" +"類別名稱,其他任意的表達式也是允許的。這可能很有用,例如,當在另一個模組中定" +"義基底類別時::" #: ../../tutorial/classes.rst:583 msgid "" @@ -814,6 +819,9 @@ msgid "" "rule is applied recursively if the base class itself is derived from some " "other class." msgstr "" +"衍伸類別定義的執行與基底類別相同。當類別物件倍建構,基底類別會被記住。這是用" +"於解析屬性參照:假如該類別中找不到一個請求的屬性,則繼續查找基底類別。假如該" +"基底類別本身也是衍伸自其他類別,則這個規則遞迴地被應用。" #: ../../tutorial/classes.rst:589 msgid "" @@ -823,6 +831,9 @@ msgid "" "searched, descending down the chain of base classes if necessary, and the " "method reference is valid if this yields a function object." msgstr "" +"關於衍伸類別的實例化並沒有特別之處: ``DerivedClassName()`` 會創建一個該類別" +"新的實例。方法參照被解析如下:對應的類別屬性會被搜尋,如果需要,沿著基底類別" +"繼承鍊往下,如果這產生一個函數物件,則方法參照有效。" #: ../../tutorial/classes.rst:595 msgid "" @@ -832,6 +843,10 @@ msgid "" "class may end up calling a method of a derived class that overrides it. " "(For C++ programmers: all methods in Python are effectively ``virtual``.)" msgstr "" +"衍伸類別可以覆寫其基底類別的方法。因為方法在呼叫同一個物件的其他方法時沒有特" +"殊的權限,所以一個呼叫同一基底類別中定義之其他方法的基底物件最終可能會呼叫一" +"個覆蓋它的衍伸類別的方法。(對於 C++ 程式員:Python 中所有方法都是有效的 " +"``virtual``)" #: ../../tutorial/classes.rst:601 msgid "" @@ -842,10 +857,14 @@ msgid "" "well. (Note that this only works if the base class is accessible as " "``BaseClassName`` in the global scope.)" msgstr "" +"一個在衍伸類別覆寫的方法可能事實上想要擴充而非單純取代基底類別中同樣名字的方" +"法。關於直接呼叫基底類別有一個簡單的方法:只要呼叫 ``BaseClassName." +"methodname(self, arguments)``。這有時對客戶端也很有用。(請注意,只有在基底類" +"別可以在全域作用域以 ``BaseClassName`` 被存取時,這才有效。)" #: ../../tutorial/classes.rst:608 msgid "Python has two built-in functions that work with inheritance:" -msgstr "" +msgstr "Python 有兩個內建函式可以用於繼承:" #: ../../tutorial/classes.rst:610 msgid "" @@ -853,6 +872,8 @@ msgid "" "will be ``True`` only if ``obj.__class__`` is :class:`int` or some class " "derived from :class:`int`." msgstr "" +"使用 :func:`isinstance` 判斷一個實例的型態:``isinstance(obj, int)`` 只有當 " +"``obj.__class__`` 是 :class:`int` 或衍伸自 :class:`int,結果會是 ``True``。" #: ../../tutorial/classes.rst:614 msgid "" @@ -861,6 +882,10 @@ msgid "" "``issubclass(float, int)`` is ``False`` since :class:`float` is not a " "subclass of :class:`int`." msgstr "" +"使用 :func:`issubclass` 判斷類別繼承: ``issubclass(bool, int)`` 會是 " +"``True`` 因為 :class:`bool` 是 :class:`int` 的子類別。但是, " +"``issubclass(float, int)``是 ``False`` 因為 :class:`float` 並不是 :class:" +"`int` 的子類別。" #: ../../tutorial/classes.rst:624 msgid "Multiple Inheritance" From 27ed0f6b0abbe7045db6897161079c32d0b48ebb Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sat, 20 Oct 2018 02:01:06 +0800 Subject: [PATCH 09/12] Fix rST warnings --- tutorial/classes.po | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 1ba0af6639d..0156758e614 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-20 00:59+0800\n" +"PO-Revision-Date: 2018-10-20 01:54+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -271,7 +271,7 @@ msgid "" "outer variable unchanged)." msgstr "" "如果名稱宣告為全域,則所有參照和賦值將直接轉到包含模組全域名稱的中間作用域。" -"要重新綁定最內層作用範圍以外找到的變數,可以使用:keyword:`nonlocal`語句;如" +"要重新綁定最內層作用範圍以外找到的變數,可以使用 :keyword:`nonlocal` 語句;如" "果沒有聲明為非本地變數,那些變數是唯讀的(嘗試寫入這樣的變數只會在最內層的作" "用域內創建一個 *new* 區域變數,保持同名的外部變數不變)。" @@ -446,8 +446,8 @@ msgid "" "that were in the class's namespace when the class object was created. So, " "if the class definition looked like this::" msgstr "" -"*屬性參照*使用 Python 中所有屬性參照使用的標準語法:``obj.name``。有效的屬性" -"名稱是創建類別物件時類別命名空間中所有的名稱。所以,如果類別定義看起來像這" +"*屬性參照* 使用 Python 中所有屬性參照使用的標準語法: ``obj.name`` 。有效的屬" +"性名稱是創建類別物件時類別命名空間中所有的名稱。所以,如果類別定義看起來像這" "樣::" #: ../../tutorial/classes.rst:276 @@ -460,8 +460,8 @@ msgid "" msgstr "" "那麼 ``MyClass.i`` 和 ``MyClass.f`` 都是有效的屬性參照,會分別回傳一個整數和" "一個函式物件。類別屬性也可以被指派(assign),所以您可以透過賦值改變 " -"``MyClass.i`` 的值。:attr:`__doc__`也是一個有效的屬性,會回傳屬於該類別的文件" -"字串(docstring):``\"A simple example class\"``。" +"``MyClass.i`` 的值。:attr:`__doc__` 也是一個有效的屬性,會回傳屬於該類別的文" +"件字串(docstring) :``\"A simple example class\"`` 。" #: ../../tutorial/classes.rst:282 msgid "" @@ -476,7 +476,7 @@ msgstr "" msgid "" "creates a new *instance* of the class and assigns this object to the local " "variable ``x``." -msgstr "建立類別的新 *實例 *, 並將此物件指派給區域變數 ``x``。" +msgstr "建立類別的新 *實例* , 並將此物件指派給區域變數 ``x`` 。" #: ../../tutorial/classes.rst:291 msgid "" @@ -545,7 +545,7 @@ msgid "" "exclusively to mean methods of class instance objects, unless explicitly " "stated otherwise.)" msgstr "" -"另一種實例屬性參照是 *方法 *。方法是 \"屬於\" 物件的函式。(在 Python 中, 對" +"另一種實例屬性參照是 *方法* 。方法是 \"屬於\" 物件的函式。(在 Python 中, 對" "類別實例來說術語方法並不是唯一的: 其他物件類型也可以有方法。 例如, 串列物件" "具有稱為 append、insert、remove、sort 等方法。但是, 在下面的討論中, 我們將" "只使用術語方法來表示類別實例物件的方法, 除非另有明確說明。)" @@ -655,8 +655,8 @@ msgid "" "not be used as a class variable because just a single list would be shared " "by all *Dog* instances::" msgstr "" -"如同在 :ref:`tut-object`的討論,共享的資料包含 :term:`mutable` 物件可以產生令" -"人驚訝的影響如串列(lists)和字典(dictionaries)。舉例來說,下列程式碼的 " +"如同在 :ref:`tut-object` 的討論,共享的資料包含 :term:`mutable` 物件可以產生" +"令人驚訝的影響如串列(lists)和字典(dictionaries)。舉例來說,下列程式碼的 " "*tricks* 串列不應該作為一個類別變數使用,因為他是一個將會被所有 *Dog* 實例共" "享的串列::" @@ -740,7 +740,9 @@ msgid "" "of that class. It is not necessary that the function definition is " "textually enclosed in the class definition: assigning a function object to a " "local variable in the class is also ok. For example::" -msgstr "任何是類別屬性的函式物件定義了一個該類別實例的方法。" +msgstr "" +"任何是類別屬性的函式物件定義了一個該類別實例的方法。 函數定義不必包含在類別定" +"義文本中:將函數物件賦值給類別中的區域變數也是可以的。例如::" #: ../../tutorial/classes.rst:527 msgid "" @@ -749,7 +751,7 @@ msgid "" "class:`C` --- ``h`` being exactly equivalent to ``g``. Note that this " "practice usually only serves to confuse the reader of a program." msgstr "" -"現在 ``f``、 ``g`` 和 ``h`` 都是類別 :class:`C` 的屬性,並涉及函數物件,所以" +"現在 ``f`` 、 ``g`` 和 ``h`` 都是類別 :class:`C` 的屬性,並涉及函數物件,所以" "他們都是類別 :class:`C` 的實例的方法 --- ``h`` 與 ``g`` 是完全一樣的。請注" "意,這種做法通常只會使該程式的讀者感到困惑。" From bc063d0a57a5673e76bbddf78927167809acc648 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sat, 20 Oct 2018 02:19:35 +0800 Subject: [PATCH 10/12] Replace all halfwidth colons with fullwidth colons --- tutorial/classes.po | 69 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index 0156758e614..f072a6bfc67 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-20 01:54+0800\n" +"PO-Revision-Date: 2018-10-20 02:15+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -340,7 +340,9 @@ msgid "" "variable binding::" msgstr "" "這是一個範例, 演示如何參照不同的作用域和命名空間, 以及 :keyword:`global` " -"和 :keyword:`global` 如何影響變數綁定::" +"和 :keyword:`global` 如何影響變數綁定:\n" +"\n" +"::" #: ../../tutorial/classes.rst:191 msgid "The output of the example code is:" @@ -448,7 +450,9 @@ msgid "" msgstr "" "*屬性參照* 使用 Python 中所有屬性參照使用的標準語法: ``obj.name`` 。有效的屬" "性名稱是創建類別物件時類別命名空間中所有的名稱。所以,如果類別定義看起來像這" -"樣::" +"樣:\n" +"\n" +"::" #: ../../tutorial/classes.rst:276 msgid "" @@ -470,7 +474,9 @@ msgid "" "For example (assuming the above class)::" msgstr "" "類別 *實例化* 使用了函式標記(function notation)。只是假裝類別物建是沒有參數" -"並回傳一個新的類別實例的函式。例如(假設是上述的類別)::" +"並回傳一個新的類別實例的函式。例如(假設是上述的類別):\n" +"\n" +"::" #: ../../tutorial/classes.rst:288 msgid "" @@ -487,7 +493,9 @@ msgid "" msgstr "" "實例化運算(“呼叫”一個類別物件)建立一個空的物件。許多類別喜歡建立一個有著自" "訂特定初始狀態實例的物件。因此,類別可以定義一個名為 :meth:`__init__` 的特別" -"方法,如下::" +"方法,如下:\n" +"\n" +"::" #: ../../tutorial/classes.rst:299 msgid "" @@ -497,7 +505,9 @@ msgid "" "by::" msgstr "" "當類別定義了 :meth:`__init__` 方法,類別實例化會自動為新建的類別實例調用 :" -"meth:`__init__`。所以在這個範例中,一個新的、初始化的實例可以如此獲得::" +"meth:`__init__`。所以在這個範例中,一個新的、初始化的實例可以如此獲得:\n" +"\n" +"::" #: ../../tutorial/classes.rst:305 msgid "" @@ -506,7 +516,9 @@ msgid "" "operator are passed on to :meth:`__init__`. For example, ::" msgstr "" "當然, :meth:`__init__` 方法可能為了更多的彈性而有參數。在這種情況下,給類別" -"實例化運算子的參數會被傳遞給 :meth:`__init__`。例如,::" +"實例化運算子的參數會被傳遞給 :meth:`__init__`。例如,:\n" +"\n" +"::" #: ../../tutorial/classes.rst:322 msgid "Instance Objects" @@ -533,7 +545,9 @@ msgstr "" "*資料屬性* 對應 Smalltalk 中的 “實例變數”, 以及 c++ 中的 \"資料成員\"。 資料" "屬性不需要宣告;和區域變數一樣, 它們在第一次賦值時就會存在。 例如, 如果" "``x``是 :class:`MyClass`在上述例子中建立的實例, 下面的程式碼將列印值 " -"``16``, 而不留下蹤跡::" +"``16``, 而不留下蹤跡:\n" +"\n" +"::" #: ../../tutorial/classes.rst:340 msgid "" @@ -570,7 +584,10 @@ msgstr "方法物件" #: ../../tutorial/classes.rst:362 msgid "Usually, a method is called right after it is bound::" -msgstr "通常,一個方法在他被綁定後立即被呼叫::" +msgstr "" +"通常,一個方法在他被綁定後立即被呼叫:\n" +"\n" +"::" #: ../../tutorial/classes.rst:366 msgid "" @@ -581,7 +598,9 @@ msgid "" msgstr "" "在 :class:`MyClass` 的例子中,這將回傳字串 ``’hello world’``。然而,沒有必要" "立即呼叫這個方法: ``x.f`` 是一個方法物件,並且可以被儲存一陣子後再被呼叫。舉" -"例來說::" +"例來說:\n" +"\n" +"::" #: ../../tutorial/classes.rst:374 msgid "will continue to print ``hello world`` until the end of time." @@ -645,7 +664,9 @@ msgid "" "of the class::" msgstr "" "一般來說,實例變數用於每一個實例的獨特資料而類別變數用於屬性和方法會被所有該" -"類別的實例所分享::" +"類別的實例所分享:\n" +"\n" +"::" #: ../../tutorial/classes.rst:427 msgid "" @@ -658,11 +679,16 @@ msgstr "" "如同在 :ref:`tut-object` 的討論,共享的資料包含 :term:`mutable` 物件可以產生" "令人驚訝的影響如串列(lists)和字典(dictionaries)。舉例來說,下列程式碼的 " "*tricks* 串列不應該作為一個類別變數使用,因為他是一個將會被所有 *Dog* 實例共" -"享的串列::" +"享的串列:\n" +"\n" +"::" #: ../../tutorial/classes.rst:450 msgid "Correct design of the class should use an instance variable instead::" -msgstr "正確的類別設計應該使用實例變數::" +msgstr "" +"正確的類別設計應該使用實例變數:\n" +"\n" +"::" #: ../../tutorial/classes.rst:474 msgid "Random Remarks" @@ -742,7 +768,9 @@ msgid "" "local variable in the class is also ok. For example::" msgstr "" "任何是類別屬性的函式物件定義了一個該類別實例的方法。 函數定義不必包含在類別定" -"義文本中:將函數物件賦值給類別中的區域變數也是可以的。例如::" +"義文本中:將函數物件賦值給類別中的區域變數也是可以的。例如:\n" +"\n" +"::" #: ../../tutorial/classes.rst:527 msgid "" @@ -759,7 +787,10 @@ msgstr "" msgid "" "Methods may call other methods by using method attributes of the ``self`` " "argument::" -msgstr "方法可以藉由使用 ``self`` 參數的方法屬性呼叫其他方法::" +msgstr "" +"方法可以藉由使用 ``self`` 參數的方法屬性呼叫其他方法:\n" +"\n" +"::" #: ../../tutorial/classes.rst:546 msgid "" @@ -799,7 +830,9 @@ msgid "" "looks like this::" msgstr "" "當然,如果沒有支援繼承,此語言功能就不得稱為 “類別”。定義衍伸類別的語法看起來" -"如下::" +"如下:\n" +"\n" +"::" #: ../../tutorial/classes.rst:576 msgid "" @@ -810,7 +843,9 @@ msgid "" msgstr "" "名稱 :class:`BaseClassName` 必須在包含衍伸類別定義的作用域中定義。替代掉基底" "類別名稱,其他任意的表達式也是允許的。這可能很有用,例如,當在另一個模組中定" -"義基底類別時::" +"義基底類別時:\n" +"\n" +"::" #: ../../tutorial/classes.rst:583 msgid "" From de690cd324ec93243c163bb6aec8e0e34d4d03fa Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Tue, 23 Oct 2018 01:42:15 +0800 Subject: [PATCH 11/12] Add translation of section 9.5.1 Multiple Inheritance --- tutorial/classes.po | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index f072a6bfc67..a99087da9fb 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-20 02:15+0800\n" +"PO-Revision-Date: 2018-10-23 01:38+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -926,13 +926,16 @@ msgstr "" #: ../../tutorial/classes.rst:624 msgid "Multiple Inheritance" -msgstr "" +msgstr "多重繼承" #: ../../tutorial/classes.rst:626 msgid "" "Python supports a form of multiple inheritance as well. A class definition " "with multiple base classes looks like this::" msgstr "" +"Python 也支援多重繼承的形式。定義一個有著多個基底類別的類別看起來像這樣子:\n" +"\n" +"::" #: ../../tutorial/classes.rst:636 msgid "" @@ -944,6 +947,11 @@ msgid "" "of :class:`Base1`, and if it was not found there, it was searched for in :" "class:`Base2`, and so on." msgstr "" +"在大多數情況下,最簡單的例子,你可以視繼承自父類別屬性的搜尋為深度優先、從左" +"到右,而非於層級結構中重疊的同一個類別中搜尋兩次。因此,假如有一個屬性在 :" +"class:`DerivedClassName` 沒有被找到,則在 :class:`Base1` 搜尋,接著(遞迴地)" +"在基底類別 :class:`Base1` 搜尋,假如在那裡沒有找到的話,會在 :class:`Base2` " +"搜尋,依此類推。" #: ../../tutorial/classes.rst:643 msgid "" @@ -953,6 +961,9 @@ msgid "" "method and is more powerful than the super call found in single-inheritance " "languages." msgstr "" +"事實上,它稍微複雜一些;方法的解析順序動態地變動以支援合作地呼叫 :func:" +"`super`。這個方法在其他的多繼承語言中稱為呼叫下一個方法(call-next-method)並" +"且比在單一繼承語言中呼叫 super 來的更強大。" #: ../../tutorial/classes.rst:649 msgid "" @@ -970,6 +981,14 @@ msgid "" "multiple inheritance. For more detail, see https://www.python.org/download/" "releases/2.3/mro/." msgstr "" +"動態排序是必要的,因為多重繼承的所有情況都表現一或多的菱形關係(其中至少一個" +"父類別可以透過最底層的多個路徑存取)。例如,所有的類別都繼承自 :class:" +"`object`,因此任何多重繼承的情況都提供了多個到達 :class:`object` 的路徑。為了" +"避免基底類別被存取多次,動態算法將搜尋順序線性化,只呼叫每個父類別一次,以保" +"留每個類別中指定的從左到右的順序。這是單調的(意思是一個類別可以被子類別化," +"而不會影響其父級的順序)。總之,這些特性使得設計具有多重繼承、可靠又可擴展的" +"類別是可能的。更多資訊,請見 https://www.python.org/download/releases/2.3/" +"mro/。" #: ../../tutorial/classes.rst:666 msgid "Private Variables" From b1e46c2e5aabbf9a36b2cc80951ab443beef34d5 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Tue, 23 Oct 2018 23:51:38 +0800 Subject: [PATCH 12/12] Add translation of section 9.6 Private Variables --- tutorial/classes.po | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tutorial/classes.po b/tutorial/classes.po index a99087da9fb..fe08cfb4787 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: Python 3.6 TW\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-06-26 18:54+0800\n" -"PO-Revision-Date: 2018-10-23 01:38+0800\n" +"PO-Revision-Date: 2018-10-23 16:22+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese Traditional (http://www.transifex.com/python-tw-doc/" "python-36-tw/language/zh-Hant/)\n" @@ -992,7 +992,7 @@ msgstr "" #: ../../tutorial/classes.rst:666 msgid "Private Variables" -msgstr "" +msgstr "私有變數" #: ../../tutorial/classes.rst:668 msgid "" @@ -1003,6 +1003,10 @@ msgid "" "a function, a method or a data member). It should be considered an " "implementation detail and subject to change without notice." msgstr "" +"Python 中沒有除了在物件內部便無法存取的“私有”實例變數。但是,大多數 Python 的" +"程式碼都遵守一個慣例:前綴為一個底線的名稱(如: ``_spam``)應被視為 API 的非" +"公有部分(無論它是函式、方法或是資料成員)。這被視為實作細節,如有更改,恕不" +"另行通知。" #: ../../tutorial/classes.rst:675 msgid "" @@ -1015,12 +1019,21 @@ msgid "" "stripped. This mangling is done without regard to the syntactic position of " "the identifier, as long as it occurs within the definition of a class." msgstr "" +"由於類別私有成員有一個有效的用例(即避免名稱與子類別定義的名稱衝突),而對這" +"種機制的支援有限,稱為 :dfn:`name mangling`。任何格式為 ``__spam`` 的辨識符" +"(只少兩個前導下底線,最多一個尾隨下底線)會被文本地替換為 " +"``_classname__spam``, ``classname`` 是前導下底線被去掉的當前類別名。只要這個" +"修飾出現在類別的定義之中,它就可以在不考慮標識符的語法位置的情況下完成。" #: ../../tutorial/classes.rst:684 msgid "" "Name mangling is helpful for letting subclasses override methods without " "breaking intraclass method calls. For example::" msgstr "" +"名稱修飾(Name mangling)對於讓子類別覆寫方法而不用破壞類別內方法呼叫是有幫助" +"的。舉例來說:\n" +"\n" +"::" #: ../../tutorial/classes.rst:706 msgid "" @@ -1029,6 +1042,8 @@ msgid "" "private. This can even be useful in special circumstances, such as in the " "debugger." msgstr "" +"請注意修飾規則是設計用於避免意外;他仍可能可以存取或修改一個被視為私有的變" +"數。這在特殊情況下甚至可能很有用,例如在除錯器。" #: ../../tutorial/classes.rst:710 msgid "" @@ -1039,6 +1054,10 @@ msgid "" "applies to ``getattr()``, ``setattr()`` and ``delattr()``, as well as when " "referencing ``__dict__`` directly." msgstr "" +"請注意,傳入 ``exec()`` 或 ``eval()`` 的程式碼不會視調用類別的名稱為當下的類" +"別;這比較接近 ``global`` 語句的效果,該效果同樣限於編譯後的位元組(byte-" +"compiled)。同樣的限制適用於 ``getattr()`` , ``setattr()`` 和 " +"``delattr()``,以及直接參照 ``__dict__`` 時。" #: ../../tutorial/classes.rst:721 msgid "Odds and Ends"