Skip to content

Commit b3a4eb3

Browse files
Copilotmattwang44
andcommitted
Translate introduction and key sections of descriptor primer
Co-authored-by: mattwang44 <24987826+mattwang44@users.noreply.github.com>
1 parent b0f9ea7 commit b3a4eb3

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

howto/descriptor.po

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ msgid ""
5757
"The \"primer\" gives a basic overview, moving gently from simple examples, "
5858
"adding one feature at a time. Start here if you're new to descriptors."
5959
msgstr ""
60+
"「入門」提供基本概述,從簡單範例開始逐步介紹,一次新增一個功能。如果你是描述器的新手,請從這裡開始。"
6061

6162
#: ../../howto/descriptor.rst:21
6263
msgid ""
6364
"The second section shows a complete, practical descriptor example. If you "
6465
"already know the basics, start there."
6566
msgstr ""
67+
"第二個章節展示完整、實用的描述器範例。如果你已經了解基礎知識,可以從那裡開始。"
6668

6769
#: ../../howto/descriptor.rst:24
6870
msgid ""
6971
"The third section provides a more technical tutorial that goes into the "
7072
"detailed mechanics of how descriptors work. Most people don't need this "
7173
"level of detail."
7274
msgstr ""
75+
"第三個章節提供更技術性的教學,深入探討描述器運作的詳細機制。大部分的人不需要這種程度的細節。"
7376

7477
#: ../../howto/descriptor.rst:28
7578
msgid ""
@@ -79,26 +82,29 @@ msgid ""
7982
"like :func:`classmethod`, :func:`staticmethod`, :func:`property`, "
8083
"and :term:`__slots__`."
8184
msgstr ""
85+
"最後一個章節提供以 C 語言撰寫的內建描述器的純 Python 等價實作。如果你好奇函式如何轉變為綁定方法,或者想了解常見工具如 :func:`classmethod`、:func:`staticmethod`、:func:`property` 和 :term:`__slots__` 的實作方式,請閱讀此章節。"
8286

8387
#: ../../howto/descriptor.rst:36
8488
msgid "Primer"
85-
msgstr ""
89+
msgstr "入門"
8690

8791
#: ../../howto/descriptor.rst:38
8892
msgid ""
8993
"In this primer, we start with the most basic possible example and then we'll "
9094
"add new capabilities one by one."
9195
msgstr ""
96+
"在此入門教學中,我們從最基礎的範例開始,然後逐一新增新功能。"
9297

9398
#: ../../howto/descriptor.rst:43
9499
msgid "Simple example: A descriptor that returns a constant"
95-
msgstr ""
100+
msgstr "簡單範例:回傳常數的描述器"
96101

97102
#: ../../howto/descriptor.rst:45
98103
msgid ""
99104
"The :class:`!Ten` class is a descriptor whose :meth:`~object.__get__` method "
100105
"always returns the constant ``10``:"
101106
msgstr ""
107+
":class:`!Ten` 類別是一個描述器,它的 :meth:`~object.__get__` 方法總是回傳常數 ``10``:"
102108

103109
#: ../../howto/descriptor.rst:48
104110
msgid ""
@@ -115,6 +121,7 @@ msgid ""
115121
"To use the descriptor, it must be stored as a class variable in another "
116122
"class:"
117123
msgstr ""
124+
"要使用描述器,必須將它儲存為另一個類別的類別變數:"
118125

119126
#: ../../howto/descriptor.rst:56
120127
msgid ""
@@ -128,6 +135,7 @@ msgid ""
128135
"An interactive session shows the difference between normal attribute lookup "
129136
"and descriptor lookup:"
130137
msgstr ""
138+
"互動式工作階段顯示一般屬性查找和描述器查找之間的差異:"
131139

132140
#: ../../howto/descriptor.rst:65
133141
msgid ""
@@ -145,33 +153,38 @@ msgid ""
145153
"descriptor instance, recognized by its ``__get__`` method. Calling that "
146154
"method returns ``10``."
147155
msgstr ""
156+
"在 ``a.x`` 屬性查找中,點運算子在類別字典中找到 ``'x': 5``。在 ``a.y`` 查找中,點運算子找到一個描述器實例,透過其 ``__get__`` 方法來識別。呼叫該方法回傳 ``10``。"
148157

149158
#: ../../howto/descriptor.rst:78
150159
msgid ""
151160
"Note that the value ``10`` is not stored in either the class dictionary or "
152161
"the instance dictionary. Instead, the value ``10`` is computed on demand."
153162
msgstr ""
163+
"請注意,數值 ``10`` 並不儲存在類別字典或實例字典中。相反地,數值 ``10`` 是按需計算的。"
154164

155165
#: ../../howto/descriptor.rst:81
156166
msgid ""
157167
"This example shows how a simple descriptor works, but it isn't very useful. "
158168
"For retrieving constants, normal attribute lookup would be better."
159169
msgstr ""
170+
"這個範例顯示了簡單描述器的運作方式,但它並不是很有用。對於取得常數,一般的屬性查找會比較好。"
160171

161172
#: ../../howto/descriptor.rst:84
162173
msgid ""
163174
"In the next section, we'll create something more useful, a dynamic lookup."
164175
msgstr ""
176+
"在下一個章節中,我們將建立更有用的東西:動態查找。"
165177

166178
#: ../../howto/descriptor.rst:88
167179
msgid "Dynamic lookups"
168-
msgstr ""
180+
msgstr "動態查找"
169181

170182
#: ../../howto/descriptor.rst:90
171183
msgid ""
172184
"Interesting descriptors typically run computations instead of returning "
173185
"constants:"
174186
msgstr ""
187+
"有趣的描述器通常執行計算而不是回傳常數:"
175188

176189
#: ../../howto/descriptor.rst:93
177190
msgid ""
@@ -195,6 +208,7 @@ msgid ""
195208
"An interactive session shows that the lookup is dynamic — it computes "
196209
"different, updated answers each time::"
197210
msgstr ""
211+
"互動式工作階段顯示查找是動態的——每次都會計算不同的更新答案: ::"
198212

199213
#: ../../howto/descriptor.rst:112
200214
msgid ""
@@ -221,10 +235,11 @@ msgid ""
221235
"parameter that lets the :meth:`~object.__get__` method learn the target "
222236
"directory. The *objtype* parameter is the class *Directory*."
223237
msgstr ""
238+
"除了顯示描述器如何執行計算外,這個範例也揭示了 :meth:`~object.__get__` 參數的目的。*self* 參數是 *size*,一個 *DirectorySize* 的實例。*obj* 參數是 *g* 或 *s*,一個 *Directory* 的實例。正是 *obj* 參數讓 :meth:`~object.__get__` 方法得知目標目錄。*objtype* 參數是類別 *Directory*。"
224239

225240
#: ../../howto/descriptor.rst:131
226241
msgid "Managed attributes"
227-
msgstr ""
242+
msgstr "受管理的屬性"
228243

229244
#: ../../howto/descriptor.rst:133
230245
msgid ""
@@ -235,13 +250,15 @@ msgid ""
235250
"and :meth:`~object.__set__` methods are triggered when the public attribute "
236251
"is accessed."
237252
msgstr ""
253+
"描述器的一個常見用途是管理對實例資料的存取。描述器被指派給類別字典中的公開屬性,而實際資料則儲存為實例字典中的私有屬性。當存取公開屬性時,會觸發描述器的 :meth:`~object.__get__` 和 :meth:`~object.__set__` 方法。"
238254

239255
#: ../../howto/descriptor.rst:139
240256
msgid ""
241257
"In the following example, *age* is the public attribute and *_age* is the "
242258
"private attribute. When the public attribute is accessed, the descriptor "
243259
"logs the lookup or update:"
244260
msgstr ""
261+
"在以下範例中,*age* 是公開屬性,*_age* 是私有屬性。當存取公開屬性時,描述器會記錄查找或更新:"
245262

246263
#: ../../howto/descriptor.rst:143
247264
msgid ""
@@ -318,13 +335,14 @@ msgstr ""
318335

319336
#: ../../howto/descriptor.rst:213
320337
msgid "Customized names"
321-
msgstr ""
338+
msgstr "自訂名稱"
322339

323340
#: ../../howto/descriptor.rst:215
324341
msgid ""
325342
"When a class uses descriptors, it can inform each descriptor about which "
326343
"variable name was used."
327344
msgstr ""
345+
"當類別使用描述器時,它可以告知每個描述器使用了哪個變數名稱。"
328346

329347
#: ../../howto/descriptor.rst:218
330348
msgid ""
@@ -427,14 +445,15 @@ msgstr ""
427445

428446
#: ../../howto/descriptor.rst:295
429447
msgid "Closing thoughts"
430-
msgstr ""
448+
msgstr "結語"
431449

432450
#: ../../howto/descriptor.rst:297
433451
msgid ""
434452
"A :term:`descriptor` is what we call any object that "
435453
"defines :meth:`~object.__get__`, :meth:`~object.__set__`, "
436454
"or :meth:`~object.__delete__`."
437455
msgstr ""
456+
":term:`描述器 <descriptor>` 是我們對任何定義了 :meth:`~object.__get__`、:meth:`~object.__set__` 或 :meth:`~object.__delete__` 的物件的稱呼。"
438457

439458
#: ../../howto/descriptor.rst:300
440459
msgid ""

0 commit comments

Comments
 (0)