1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) 2001-2022, Python Software Foundation
1
+ # Copyright (C) 2001-2024, Python Software Foundation
3
2
# This file is distributed under the same license as the Python package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
3
#
6
- #, fuzzy
4
+ # Translators:
5
+ # CTHua <illiew2470+pythonTW@gmail.com>, 2023
6
+ # Matt Wang <mattwang44@gmail.com>, 2024
7
7
msgid ""
8
8
msgstr ""
9
9
"Project-Id-Version : Python 3.12\n "
10
10
"Report-Msgid-Bugs-To : \n "
11
- "POT-Creation-Date : 2023-11-30 00:03+0000\n "
12
- "PO-Revision-Date : YEAR-MO-DA HO:MI+ZONE\n "
13
- "Last-Translator : FULL NAME <EMAIL@ADDRESS>\n "
14
- "Language-Team : LANGUAGE <LL@li.org>\n "
11
+ "POT-Creation-Date : 2024-02-24 16:01+0800\n "
12
+ "PO-Revision-Date : 2024-05-13 19:30+0000\n "
13
+ "Last-Translator : Matt Wang <mattwang44@gmail.com>\n "
14
+ "Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
15
+ "tw)\n "
15
16
"Language : zh_TW\n "
16
17
"MIME-Version : 1.0\n "
17
18
"Content-Type : text/plain; charset=UTF-8\n "
18
19
"Content-Transfer-Encoding : 8bit\n "
20
+ "Plural-Forms : nplurals=2; plural=n != 1;\n "
19
21
20
22
#: ../../howto/enum.rst:3
21
23
msgid "Enum HOWTO"
22
- msgstr ""
24
+ msgstr "如何使用列舉 (Enum) "
23
25
24
26
#: ../../howto/enum.rst:9
27
+ #, fuzzy
25
28
msgid ""
26
29
"An :class:`Enum` is a set of symbolic names bound to unique values. They "
27
30
"are similar to global variables, but they offer a more useful :func:"
28
31
"`repr()`, grouping, type-safety, and a few other features."
29
32
msgstr ""
33
+ ":class:`Enum` 是一組綁定唯一值的符號名稱集合。與全域變數類似,但提供更有用"
34
+ "的 :func:`repr()`、分組功能、型別安全以及其他若干特殊功能。"
30
35
31
36
#: ../../howto/enum.rst:13
37
+ #, fuzzy
32
38
msgid ""
33
39
"They are most useful when you have a variable that can take one of a limited "
34
40
"selection of values. For example, the days of the week::"
35
41
msgstr ""
42
+ "當你有一個變數可以取值為限定的一部分時,最有用。例如:一周中的日期: ::"
36
43
37
44
#: ../../howto/enum.rst:26
38
45
msgid "Or perhaps the RGB primary colors::"
39
- msgstr ""
46
+ msgstr "或許是 RGB 主要色彩: :: "
40
47
41
48
#: ../../howto/enum.rst:34
49
+ #, fuzzy
42
50
msgid ""
43
51
"As you can see, creating an :class:`Enum` is as simple as writing a class "
44
52
"that inherits from :class:`Enum` itself."
45
53
msgstr ""
54
+ "你可以看出來,建立一個:class:`Enum`就像編寫一個從自身繼承的:class:`Enum`類"
55
+ "別。"
46
56
47
57
#: ../../howto/enum.rst:37
48
58
msgid "Case of Enum Members"
49
- msgstr ""
59
+ msgstr "列舉成員的情況 "
50
60
51
61
#: ../../howto/enum.rst:39
62
+ #, fuzzy
52
63
msgid ""
53
64
"Because Enums are used to represent constants, and to help avoid issues with "
54
65
"name clashes between mixin-class methods/attributes and enum names, we "
55
66
"strongly recommend using UPPER_CASE names for members, and will be using "
56
67
"that style in our examples."
57
68
msgstr ""
69
+ "由於列舉用於表示常數,我們建議使用大寫命名法,以此命名成員。在我們的範例中也"
70
+ "會採用這種風格。"
58
71
59
72
#: ../../howto/enum.rst:44
73
+ #, fuzzy
60
74
msgid ""
61
75
"Depending on the nature of the enum a member's value may or may not be "
62
76
"important, but either way that value can be used to get the corresponding "
63
77
"member::"
64
78
msgstr ""
79
+ "根據 enum 的性質,成員的值可能很重要,也可能不太重要,但無論如何這個值都可以"
80
+ "用來取得對應的成員: ::"
65
81
66
82
#: ../../howto/enum.rst:51
83
+ #, fuzzy
67
84
msgid ""
68
85
"As you can see, the ``repr()`` of a member shows the enum name, the member "
69
86
"name, and the value. The ``str()`` of a member shows only the enum name and "
70
87
"member name::"
71
88
msgstr ""
89
+ "你可以看到,一個成員的 ``repr()`` 會顯示列舉名稱、成員名稱和值。而該成員的 "
90
+ "``str()`` 僅會顯示列舉名稱和成員名稱: ::"
72
91
73
92
#: ../../howto/enum.rst:58
93
+ #, fuzzy
74
94
msgid "The *type* of an enumeration member is the enum it belongs to::"
75
- msgstr ""
95
+ msgstr "列舉成員的 *型別* 即其所屬的列舉:注意:保留 rst 格式符號: :: "
76
96
77
97
#: ../../howto/enum.rst:65
78
98
msgid "Enum members have an attribute that contains just their :attr:`name`::"
79
- msgstr ""
99
+ msgstr "列舉成員具有一個屬性,其中僅包含它們的 :attr:`name`: :: "
80
100
81
101
#: ../../howto/enum.rst:70
102
+ #, fuzzy
82
103
msgid "Likewise, they have an attribute for their :attr:`value`::"
83
- msgstr ""
104
+ msgstr "同樣地,它們具有一個屬性用於它們的 :attr:`value` 值: :: "
84
105
85
106
#: ../../howto/enum.rst:76
107
+ #, fuzzy
86
108
msgid ""
87
109
"Unlike many languages that treat enumerations solely as name/value pairs, "
88
110
"Python Enums can have behavior added. For example, :class:`datetime.date` "
@@ -92,226 +114,291 @@ msgid ""
92
114
"to the :class:`Weekday` enum to extract the day from the :class:`date` "
93
115
"instance and return the matching enum member::"
94
116
msgstr ""
117
+ "與其他把列舉視為純名稱/值對的語言不同,Python 的 Enums 可添加行為。例如,:"
118
+ "class:`datetime.date` 有兩個回傳週幾星期幾的方法::meth:`weekday` 和 :meth:"
119
+ "`isoweekday`。差異在於一個從0-6算起,另一個從1-7算起。我們可以新增一個方法到:"
120
+ "class:`Weekday` 列舉中 ,以提取日期實例的天數並回傳相應的列舉成員來追蹤它自 "
121
+ "己: ::"
95
122
96
123
#: ../../howto/enum.rst:88
97
124
msgid "The complete :class:`Weekday` enum now looks like this::"
98
- msgstr ""
125
+ msgstr "完整的 :class:`Weekday` 列舉現在看起來像是這樣: :: "
99
126
100
127
#: ../../howto/enum.rst:103
101
128
msgid "Now we can find out what today is! Observe::"
102
- msgstr ""
129
+ msgstr "現在我們可以找出今天是哪一天了!請觀察: :: "
103
130
104
131
#: ../../howto/enum.rst:109
132
+ #, fuzzy
105
133
msgid ""
106
134
"Of course, if you're reading this on some other day, you'll see that day "
107
135
"instead."
108
- msgstr ""
136
+ msgstr "當然,如果你是在其他日期閱讀這篇文章,你會看到該天的日期。 "
109
137
110
138
#: ../../howto/enum.rst:111
139
+ #, fuzzy
111
140
msgid ""
112
141
"This :class:`Weekday` enum is great if our variable only needs one day, but "
113
142
"what if we need several? Maybe we're writing a function to plot chores "
114
143
"during a week, and don't want to use a :class:`list` -- we could use a "
115
144
"different type of :class:`Enum`::"
116
145
msgstr ""
146
+ "這個 :class:`Weekday` 列舉型別對於只需要一天的變數很方便,但如果我們需要多天"
147
+ "呢?也許我們正在撰寫一個函式,要在整週繪製家務事項,而不想使用 :class:`list` "
148
+ "-- 我們可以使用另一種 :class:`Enum` 型別: ::"
117
149
118
150
#: ../../howto/enum.rst:126
151
+ #, fuzzy
119
152
msgid ""
120
153
"We've changed two things: we're inherited from :class:`Flag`, and the values "
121
154
"are all powers of 2."
122
- msgstr ""
155
+ msgstr "我們做了兩件事:一是繼承 :class:`Flag` 類別,二是所有的值都是2的乘方。 "
123
156
124
157
#: ../../howto/enum.rst:129
125
158
msgid ""
126
159
"Just like the original :class:`Weekday` enum above, we can have a single "
127
160
"selection::"
128
- msgstr ""
161
+ msgstr "就像原本的 :class:`Weekday` 列舉一樣,我們可以進行單一選擇: :: "
129
162
130
163
#: ../../howto/enum.rst:135
131
164
msgid ""
132
165
"But :class:`Flag` also allows us to combine several members into a single "
133
166
"variable::"
134
- msgstr ""
167
+ msgstr "但是 :class:`Flag` 也允許我們將數個成員結合為一個變數: :: "
135
168
136
169
#: ../../howto/enum.rst:142
137
170
msgid "You can even iterate over a :class:`Flag` variable::"
138
- msgstr ""
171
+ msgstr "你甚至可以疊代一個 :class:`Flag` 變數: :: "
139
172
140
173
#: ../../howto/enum.rst:149
141
174
msgid "Okay, let's get some chores set up::"
142
- msgstr ""
175
+ msgstr "好的,讓我們進行一些設定: :: "
143
176
144
177
#: ../../howto/enum.rst:157
178
+ #, fuzzy
145
179
msgid "And a function to display the chores for a given day::"
146
- msgstr ""
180
+ msgstr "以下是給定一個日期的家務事項顯示函式: :: "
147
181
148
182
#: ../../howto/enum.rst:167
183
+ #, fuzzy
149
184
msgid ""
150
185
"In cases where the actual values of the members do not matter, you can save "
151
186
"yourself some work and use :func:`auto()` for the values::"
152
187
msgstr ""
188
+ "如果成員的實際值不重要,你可以省去一些工作,並使用 :func:`auto()` 替代數"
189
+ "值: ::"
153
190
154
191
#: ../../howto/enum.rst:186
155
192
msgid "Programmatic access to enumeration members and their attributes"
156
- msgstr ""
193
+ msgstr "可以用程式化的方式存取列舉成員及其屬性 "
157
194
158
195
#: ../../howto/enum.rst:188
196
+ #, fuzzy
159
197
msgid ""
160
198
"Sometimes it's useful to access members in enumerations programmatically (i."
161
199
"e. situations where ``Color.RED`` won't do because the exact color is not "
162
200
"known at program-writing time). ``Enum`` allows such access::"
163
201
msgstr ""
202
+ "有時候,以程式方式存取列舉中的成員是很有用且必要的(例如在編寫程式時無法確定"
203
+ "正確顏色,因此使用 ``Color.RED`` 就不合適)。在這種情況下,可以利用 ``Enum`` "
204
+ "來存取: ::"
164
205
165
206
#: ../../howto/enum.rst:197
166
207
msgid "If you want to access enum members by *name*, use item access::"
167
- msgstr ""
208
+ msgstr "如果你想要透過 *name* 存取列舉成員,請使用項目來存取: :: "
168
209
169
210
#: ../../howto/enum.rst:204
211
+ #, fuzzy
170
212
msgid "If you have an enum member and need its :attr:`name` or :attr:`value`::"
171
213
msgstr ""
214
+ "如果你有一個列舉的成員,並需要獲取其 :attr:`name` 或 :attr:`value`屬性: ::"
172
215
173
216
#: ../../howto/enum.rst:214
174
217
msgid "Duplicating enum members and values"
175
- msgstr ""
218
+ msgstr "複製列舉成員和值 "
176
219
177
220
#: ../../howto/enum.rst:216
178
221
msgid "Having two enum members with the same name is invalid::"
179
- msgstr ""
222
+ msgstr "擁有兩個同名的列舉成員是無效的: :: "
180
223
181
224
#: ../../howto/enum.rst:226
225
+ #, fuzzy
182
226
msgid ""
183
227
"However, an enum member can have other names associated with it. Given two "
184
228
"entries ``A`` and ``B`` with the same value (and ``A`` defined first), ``B`` "
185
229
"is an alias for the member ``A``. By-value lookup of the value of ``A`` "
186
230
"will return the member ``A``. By-name lookup of ``A`` will return the "
187
231
"member ``A``. By-name lookup of ``B`` will also return the member ``A``::"
188
232
msgstr ""
233
+ "然而,列舉成員可以有其它名稱與之相關聯。假設有兩個項目 ``A`` 與 ``B``,且其值"
234
+ "相同 (且``A``定義在前面),則 ``B`` 是成員 ``A`` 的別名。透過取得 \" by-"
235
+ "value\" 屬性來查找 \" A\" 的值會回傳成員\" A\" ; 透過 \" by-name\" 方式查找\" A\" 也"
236
+ "會回傳成員\" A\" ;透過 \" by-name\" 方式查找\" B\" ,同樣也會回傳 成員 ``A``: ::"
189
237
190
238
#: ../../howto/enum.rst:247
239
+ #, fuzzy
191
240
msgid ""
192
241
"Attempting to create a member with the same name as an already defined "
193
242
"attribute (another member, a method, etc.) or attempting to create an "
194
243
"attribute with the same name as a member is not allowed."
195
244
msgstr ""
245
+ "嘗試建立一個與已定義的屬性(另一個成員、方法等)同名的成員,或者嘗試建立一個"
246
+ "與成 員同名的屬性是不被允許的。"
196
247
197
248
#: ../../howto/enum.rst:253
198
249
msgid "Ensuring unique enumeration values"
199
- msgstr ""
250
+ msgstr "確保列舉值唯一 "
200
251
201
252
#: ../../howto/enum.rst:255
253
+ #, fuzzy
202
254
msgid ""
203
255
"By default, enumerations allow multiple names as aliases for the same value. "
204
256
"When this behavior isn't desired, you can use the :func:`unique` decorator::"
205
257
msgstr ""
258
+ "預設情況下,列舉型別允許使用多個名稱作為相同值的別名。當不希望這種行為時,可"
259
+ "以使用 :func:`unique` 裝飾器: ::"
206
260
207
261
#: ../../howto/enum.rst:272
208
262
msgid "Using automatic values"
209
- msgstr ""
263
+ msgstr "使用自動產生的值 "
210
264
211
265
#: ../../howto/enum.rst:274
266
+ #, fuzzy
212
267
msgid "If the exact value is unimportant you can use :class:`auto`::"
213
- msgstr ""
268
+ msgstr "如果精確值不重要,可以使用 :class:`auto`: :: "
214
269
215
270
#: ../../howto/enum.rst:285
271
+ #, fuzzy
216
272
msgid ""
217
273
"The values are chosen by :func:`_generate_next_value_`, which can be "
218
274
"overridden::"
219
- msgstr ""
275
+ msgstr "值是由 :func:`_generate_next_value_` 決定的,可以被覆寫: :: "
220
276
221
277
#: ../../howto/enum.rst:304
278
+ #, fuzzy
222
279
msgid ""
223
280
"The :meth:`_generate_next_value_` method must be defined before any members."
224
- msgstr ""
281
+ msgstr "在任何成員之前都必須先定義 :meth:`_generate_next_value_` 方法。 "
225
282
226
283
#: ../../howto/enum.rst:307
227
284
msgid "Iteration"
228
- msgstr ""
285
+ msgstr "疊代 "
229
286
230
287
#: ../../howto/enum.rst:309
288
+ #, fuzzy
231
289
msgid "Iterating over the members of an enum does not provide the aliases::"
232
- msgstr ""
290
+ msgstr "逐一列舉列舉型別的成員時不提供其別名: :: "
233
291
234
292
#: ../../howto/enum.rst:316
293
+ #, fuzzy
235
294
msgid ""
236
295
"Note that the aliases ``Shape.ALIAS_FOR_SQUARE`` and ``Weekday.WEEKEND`` "
237
296
"aren't shown."
238
297
msgstr ""
298
+ "注意:別名 ``Shape.ALIAS_FOR_SQUARE`` 和 ``Weekday.WEEKEND`` 沒有顯示。"
239
299
240
300
#: ../../howto/enum.rst:318
301
+ #, fuzzy
241
302
msgid ""
242
303
"The special attribute ``__members__`` is a read-only ordered mapping of "
243
304
"names to members. It includes all names defined in the enumeration, "
244
305
"including the aliases::"
245
306
msgstr ""
307
+ "特殊屬性 ``__members__`` 是一個只能讀取的有序映射,從名稱到成員。它包括了列舉"
308
+ "中定義的所有名稱,包括別名: ::"
246
309
247
310
#: ../../howto/enum.rst:330
311
+ #, fuzzy
248
312
msgid ""
249
313
"The ``__members__`` attribute can be used for detailed programmatic access "
250
314
"to the enumeration members. For example, finding all the aliases::"
251
315
msgstr ""
316
+ "``__members__`` 屬性可用於對列舉成員進行詳細的程式設計訪問。例如,查找所有別"
317
+ "名: ::"
252
318
253
319
#: ../../howto/enum.rst:338
320
+ #, fuzzy
254
321
msgid ""
255
322
"Aliases for flags include values with multiple flags set, such as ``3``, and "
256
323
"no flags set, i.e. ``0``."
257
324
msgstr ""
325
+ "輸入參數的別名可以使用在有多個指令旗標時,例如 `3`;也可用於無任何指令旗標"
326
+ "時,即 `0`。"
258
327
259
328
#: ../../howto/enum.rst:343
260
329
msgid "Comparisons"
261
- msgstr ""
330
+ msgstr "比較 "
262
331
263
332
#: ../../howto/enum.rst:345
333
+ #, fuzzy
264
334
msgid "Enumeration members are compared by identity::"
265
- msgstr ""
335
+ msgstr "列舉成員按識別性進行比較: :: "
266
336
267
337
#: ../../howto/enum.rst:354
338
+ #, fuzzy
268
339
msgid ""
269
340
"Ordered comparisons between enumeration values are *not* supported. Enum "
270
341
"members are not integers (but see `IntEnum`_ below)::"
271
342
msgstr ""
343
+ "不支援列舉值之間的排序比較。列舉成員並非整數(但下方可參考 `IntEnum`_): ::"
272
344
273
345
#: ../../howto/enum.rst:362
346
+ #, fuzzy
274
347
msgid "Equality comparisons are defined though::"
275
- msgstr ""
348
+ msgstr "等式比較是透過以下定義: :: "
276
349
277
350
#: ../../howto/enum.rst:371
351
+ #, fuzzy
278
352
msgid ""
279
353
"Comparisons against non-enumeration values will always compare not equal "
280
354
"(again, :class:`IntEnum` was explicitly designed to behave differently, see "
281
355
"below)::"
282
356
msgstr ""
357
+ "對不包含列舉值的比較總是會得到「不相等」(再一次地,:class:`IntEnum` 是有特別"
358
+ "定義的行為,詳情見下文): ::"
283
359
284
360
#: ../../howto/enum.rst:380
361
+ #, fuzzy
285
362
msgid ""
286
363
"It is possible to reload modules -- if a reloaded module contains enums, "
287
364
"they will be recreated, and the new members may not compare identical/equal "
288
365
"to the original members."
289
366
msgstr ""
367
+ "可以重新加載模組——如果重新加載的模組包含列舉,它們將被重新建立,並且新成員可"
368
+ "能不會與原始成員相同/相等。"
290
369
291
370
#: ../../howto/enum.rst:385
292
371
msgid "Allowed members and attributes of enumerations"
293
- msgstr ""
372
+ msgstr "列舉型別中的允許成員和屬性 "
294
373
295
374
#: ../../howto/enum.rst:387
375
+ #, fuzzy
296
376
msgid ""
297
377
"Most of the examples above use integers for enumeration values. Using "
298
378
"integers is short and handy (and provided by default by the `Functional "
299
379
"API`_), but not strictly enforced. In the vast majority of use-cases, one "
300
380
"doesn't care what the actual value of an enumeration is. But if the value "
301
381
"*is* important, enumerations can have arbitrary values."
302
382
msgstr ""
383
+ "大部分上面的範例都使用整數來作為列舉值。使用整數即方便又快速(而且Functional "
384
+ "API預設也會支援),但不是強制性的做法。在極大多數情況下,一個資料列舉實際所代"
385
+ "表的值不重要。但如果該值很重要,你仍可以隨意指定任何需求所涵蓋到之列舉值。"
303
386
304
387
#: ../../howto/enum.rst:393
388
+ #, fuzzy
305
389
msgid ""
306
390
"Enumerations are Python classes, and can have methods and special methods as "
307
391
"usual. If we have this enumeration::"
308
392
msgstr ""
393
+ "列舉是 Python 中的一種類別,可像慣例中的其他類別一樣,具有方法和特殊方法。若"
394
+ "我們定義以下列舉: ::"
309
395
310
396
#: ../../howto/enum.rst:413
311
397
msgid "Then::"
312
- msgstr ""
398
+ msgstr "接著是: :: "
313
399
314
400
#: ../../howto/enum.rst:422
401
+ #, fuzzy
315
402
msgid ""
316
403
"The rules for what is allowed are as follows: names that start and end with "
317
404
"a single underscore are reserved by enum and cannot be used; all other "
@@ -320,123 +407,165 @@ msgid ""
320
407
"`__add__`, etc.), descriptors (methods are also descriptors), and variable "
321
408
"names listed in :attr:`_ignore_`."
322
409
msgstr ""
410
+ "定義列舉時,需注意以下規則:命名以一個底線開頭和結尾的名稱保留給 enum ,不能"
411
+ "使用;除了特殊方法(例如: :meth:`__str__`, :meth:`__add__` 等)、描述符 (方法"
412
+ "也是描述符) 以及在 :attr:`_ignore_` 中列出的變數名之外,定義於列舉內部的所有"
413
+ "屬性都會成為此列舉類別的成員。"
323
414
324
415
#: ../../howto/enum.rst:429
416
+ #, fuzzy
325
417
msgid ""
326
418
"Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__`, "
327
419
"any value(s) given to the enum member will be passed into those methods. See "
328
420
"`Planet`_ for an example."
329
421
msgstr ""
422
+ "請注意:如果你的列舉定義了 ``__new__`` 和/或 ``__init__`` 方法,則任何指定給"
423
+ "該列舉成員的值都將傳遞到這些方法中。請參考 `Planet`_ 的範例。"
330
424
331
425
#: ../../howto/enum.rst:435
426
+ #, fuzzy
332
427
msgid ""
333
428
"The :meth:`__new__` method, if defined, is used during creation of the Enum "
334
429
"members; it is then replaced by Enum's :meth:`__new__` which is used after "
335
430
"class creation for lookup of existing members. See :ref:`new-vs-init` for "
336
431
"more details."
337
432
msgstr ""
433
+ "__new__` 方法(如果定義)將在建立 Enum 成員期間使用;然後它被 Enum 的 "
434
+ "__new__` 替換,該 __new__` 在類別建立後用於尋找現有成員。有關更多詳細資訊,請"
435
+ "參閱:ref:`new-vs-init`。"
338
436
339
437
#: ../../howto/enum.rst:442
340
438
msgid "Restricted Enum subclassing"
341
- msgstr ""
439
+ msgstr "受限列舉子類別化 "
342
440
343
441
#: ../../howto/enum.rst:444
442
+ #, fuzzy
344
443
msgid ""
345
444
"A new :class:`Enum` class must have one base enum class, up to one concrete "
346
445
"data type, and as many :class:`object`-based mixin classes as needed. The "
347
446
"order of these base classes is::"
348
447
msgstr ""
448
+ "一個新的 :class:`Enum` 類別必須擁有一個基礎列舉(enum)類別、不超過一種具體的資"
449
+ "料型別(data type),以及所需的任意數量使用 :class:`object` 為基礎(mixin) 的混"
450
+ "合類別。這些基礎類別(base classes)之間的順序為: ::"
349
451
350
452
#: ../../howto/enum.rst:451
453
+ #, fuzzy
351
454
msgid ""
352
455
"Also, subclassing an enumeration is allowed only if the enumeration does not "
353
456
"define any members. So this is forbidden::"
354
457
msgstr ""
458
+ "同時,只有在列舉型別未定義任何成員時才允許子類化enumeration。因此,這是被禁止"
459
+ "的: ::"
355
460
356
461
#: ../../howto/enum.rst:461
357
462
msgid "But this is allowed::"
358
- msgstr ""
463
+ msgstr "但這是允許的: :: "
359
464
360
465
#: ../../howto/enum.rst:472
466
+ #, fuzzy
361
467
msgid ""
362
468
"Allowing subclassing of enums that define members would lead to a violation "
363
469
"of some important invariants of types and instances. On the other hand, it "
364
470
"makes sense to allow sharing some common behavior between a group of "
365
471
"enumerations. (See `OrderedEnum`_ for an example.)"
366
472
msgstr ""
473
+ "允許定義成員的列舉型別可以被繼承,但這也會違反一些重要的類型和實例不變數。然"
474
+ "而,在一組列舉中,允許共享某些通用的行為是有道理的。(例如參考 `OrderedEnum`_ "
475
+ "之範例) 。"
367
476
368
477
#: ../../howto/enum.rst:481
478
+ #, fuzzy
369
479
msgid "Dataclass support"
370
- msgstr ""
480
+ msgstr "資料類支援 "
371
481
372
482
#: ../../howto/enum.rst:483
483
+ #, fuzzy
373
484
msgid ""
374
485
"When inheriting from a :class:`~dataclasses.dataclass`, the :meth:`~Enum."
375
486
"__repr__` omits the inherited class' name. For example::"
376
487
msgstr ""
488
+ "當從:class:`~dataclasses.dataclass` 繼承時,:meth:`~Enum.__repr__` 會省略繼承"
489
+ "的類別的名稱。例如::"
377
490
378
491
#: ../../howto/enum.rst:500
492
+ #, fuzzy
379
493
msgid ""
380
494
"Use the :func:`!dataclass` argument ``repr=False`` to use the standard :func:"
381
495
"`repr`."
382
- msgstr ""
496
+ msgstr "使用 :func:`!dataclass` 參數 ``repr=False`` 來使用標準 :func:`repr`。 "
383
497
384
498
#: ../../howto/enum.rst:503
499
+ #, fuzzy
385
500
msgid ""
386
501
"Only the dataclass fields are shown in the value area, not the dataclass' "
387
502
"name."
388
- msgstr ""
503
+ msgstr "值區域中僅顯示資料類欄位,而不顯示資料類名稱。 "
389
504
390
505
#: ../../howto/enum.rst:509
391
506
msgid "Pickling"
392
- msgstr ""
507
+ msgstr "Pickling "
393
508
394
509
#: ../../howto/enum.rst:511
395
510
msgid "Enumerations can be pickled and unpickled::"
396
- msgstr ""
511
+ msgstr "列舉可以被 pickle 和 unpickle: :: "
397
512
398
513
#: ../../howto/enum.rst:518
514
+ #, fuzzy
399
515
msgid ""
400
516
"The usual restrictions for pickling apply: picklable enums must be defined "
401
517
"in the top level of a module, since unpickling requires them to be "
402
518
"importable from that module."
403
519
msgstr ""
520
+ "通常對於 pickling 有一些限制:可 pickle 的列舉型別必須在模組的最上層定義,因"
521
+ "為反序列化需要它們從該模組中 importable。"
404
522
405
523
#: ../../howto/enum.rst:524
524
+ #, fuzzy
406
525
msgid ""
407
526
"With pickle protocol version 4 it is possible to easily pickle enums nested "
408
527
"in other classes."
409
528
msgstr ""
529
+ "從 pickle 協議版本 4 開始,嵌套在其他類別內的 enums 可以方便地進行序列化"
530
+ "(pickle)。"
410
531
411
532
#: ../../howto/enum.rst:527
533
+ #, fuzzy
412
534
msgid ""
413
535
"It is possible to modify how enum members are pickled/unpickled by defining :"
414
536
"meth:`__reduce_ex__` in the enumeration class. The default method is by-"
415
537
"value, but enums with complicated values may want to use by-name::"
416
538
msgstr ""
539
+ "可以透過在列舉類別中定義 :meth:`__reduce_ex__` 來修改列舉成員的取捨(pickled/"
540
+ "unpickled)方式: ::"
417
541
418
542
#: ../../howto/enum.rst:537
543
+ #, fuzzy
419
544
msgid ""
420
545
"Using by-name for flags is not recommended, as unnamed aliases will not "
421
546
"unpickle."
422
- msgstr ""
547
+ msgstr "不建議旗標使用依名稱,因為未命名的別名不會被 unpickle。 "
423
548
424
549
#: ../../howto/enum.rst:542
425
550
msgid "Functional API"
426
- msgstr ""
551
+ msgstr "功能性 API "
427
552
428
553
#: ../../howto/enum.rst:544
429
554
msgid ""
430
555
"The :class:`Enum` class is callable, providing the following functional API::"
431
- msgstr ""
556
+ msgstr ":class:`Enum` 類別是可呼叫物件,並提供以下功能性 API: :: "
432
557
433
558
#: ../../howto/enum.rst:554
559
+ #, fuzzy
434
560
msgid ""
435
561
"The semantics of this API resemble :class:`~collections.namedtuple`. The "
436
562
"first argument of the call to :class:`Enum` is the name of the enumeration."
437
563
msgstr ""
564
+ "這個 API 的語義類似 :class:`~collections.namedtuple`。叫用 :class:`Enum` 的第"
565
+ "一個引數是列舉型別的名稱。"
438
566
439
567
#: ../../howto/enum.rst:557
568
+ #, fuzzy
440
569
msgid ""
441
570
"The second argument is the *source* of enumeration member names. It can be "
442
571
"a whitespace-separated string of names, a sequence of names, a sequence of 2-"
@@ -447,128 +576,160 @@ msgid ""
447
576
"class derived from :class:`Enum` is returned. In other words, the above "
448
577
"assignment to :class:`Animal` is equivalent to::"
449
578
msgstr ""
579
+ "第二個參數是列舉成員名稱的「來源」。它可以是由空格分隔的字串、一系列名稱、具"
580
+ "有鍵值對的 2 元序列,或者映射(例如字典),其中包含了名稱和相應值。最後兩個選項"
581
+ "使得能夠將任意值指定給列舉;其他則自動分配從 1 開始增加的整數 (使用 "
582
+ "``start`` 參數可指定不同的起始值) 。回傳一個衍生自 :class:`Enum` 的新類別。換"
583
+ "句話說,上面賦予 :class:`Animal` 的功能等價於: ::"
450
584
451
585
#: ../../howto/enum.rst:573
586
+ #, fuzzy
452
587
msgid ""
453
588
"The reason for defaulting to ``1`` as the starting number and not ``0`` is "
454
589
"that ``0`` is ``False`` in a boolean sense, but by default enum members all "
455
590
"evaluate to ``True``."
456
591
msgstr ""
592
+ "預設將起始數字設為 ``1`` 而非 ``0`` 的原因是,布林運算中 ``0`` 為 ``False``, "
593
+ "但列舉型別中成員的預設值皆為真(evaluate to True)。"
457
594
458
595
#: ../../howto/enum.rst:577
596
+ #, fuzzy
459
597
msgid ""
460
598
"Pickling enums created with the functional API can be tricky as frame stack "
461
599
"implementation details are used to try and figure out which module the "
462
600
"enumeration is being created in (e.g. it will fail if you use a utility "
463
601
"function in a separate module, and also may not work on IronPython or "
464
602
"Jython). The solution is to specify the module name explicitly as follows::"
465
603
msgstr ""
604
+ "使用函式 API 建立的列舉型別可能會比較棘手,因為框架堆疊實現細節被用來嘗試找出"
605
+ "建立列舉型別的模組(例如,如果在另一個模組中使用實用工具函式則失敗,在 "
606
+ "IronPython 或 Jython 上也可能無法正常運作)。解決方案是明確指定模組名稱,如下"
607
+ "所示: ::"
466
608
467
609
#: ../../howto/enum.rst:587
610
+ #, fuzzy
468
611
msgid ""
469
612
"If ``module`` is not supplied, and Enum cannot determine what it is, the new "
470
613
"Enum members will not be unpicklable; to keep errors closer to the source, "
471
614
"pickling will be disabled."
472
615
msgstr ""
616
+ "如果未提供``module``,且Enum不能確定它是什麼,新的Enum成員將無法進行反序列"
617
+ "化; 為了讓錯誤更接近源頭,pickling會被禁用。"
473
618
474
619
#: ../../howto/enum.rst:591
620
+ #, fuzzy
475
621
msgid ""
476
622
"The new pickle protocol 4 also, in some circumstances, relies on :attr:"
477
623
"`~definition.__qualname__` being set to the location where pickle will be "
478
624
"able to find the class. For example, if the class was made available in "
479
625
"class SomeData in the global scope::"
480
626
msgstr ""
627
+ "新的 pickle 協議 4 在某些情況下還依賴於 :attr:``~definition.__qualname__`` 設"
628
+ "置為 pickle 能找到該類別位置的屬性。舉例而言,如果在全域範圍內建立了一個名為 "
629
+ "SomeData 的類別: ::"
481
630
482
631
#: ../../howto/enum.rst:598
483
632
msgid "The complete signature is::"
484
- msgstr ""
633
+ msgstr "完整的函式為: :: "
485
634
486
635
#: ../../howto/enum.rst:610
487
636
msgid "*value*: What the new enum class will record as its name."
488
- msgstr ""
637
+ msgstr "*value*:新列舉類別將記錄為其名稱。 "
489
638
490
639
#: ../../howto/enum.rst:612
640
+ #, fuzzy
491
641
msgid ""
492
642
"*names*: The enum members. This can be a whitespace- or comma-separated "
493
643
"string (values will start at 1 unless otherwise specified)::"
494
644
msgstr ""
645
+ "*names*:列出 enum 的成員,這應為一個換行或以逗號分隔的字串(否則值將從 1 開"
646
+ "始): ::"
495
647
496
648
#: ../../howto/enum.rst:617
497
649
msgid "or an iterator of names::"
498
- msgstr ""
650
+ msgstr "或一個名稱的疊代器: :: "
499
651
500
652
#: ../../howto/enum.rst:621
501
653
msgid "or an iterator of (name, value) pairs::"
502
- msgstr ""
654
+ msgstr "或是一個 (name, value) 對的疊代器: :: "
503
655
504
656
#: ../../howto/enum.rst:625
505
657
msgid "or a mapping::"
506
- msgstr ""
658
+ msgstr "或是一個對映: :: "
507
659
508
660
#: ../../howto/enum.rst:629
661
+ #, fuzzy
509
662
msgid "*module*: name of module where new enum class can be found."
510
- msgstr ""
663
+ msgstr "*module*:可以找到新列舉類別的模組的名稱。 "
511
664
512
665
#: ../../howto/enum.rst:631
666
+ #, fuzzy
513
667
msgid "*qualname*: where in module new enum class can be found."
514
- msgstr ""
668
+ msgstr "*qualname*:在模組中可以找到新列舉類別的位置。 "
515
669
516
670
#: ../../howto/enum.rst:633
517
671
msgid "*type*: type to mix in to new enum class."
518
- msgstr ""
672
+ msgstr "*type*:混合到新列舉類別中的型別。 "
519
673
520
674
#: ../../howto/enum.rst:635
521
675
msgid "*start*: number to start counting at if only names are passed in."
522
- msgstr ""
676
+ msgstr "*start*:如果僅傳入名稱,則從該數字開始計數。 "
523
677
524
678
#: ../../howto/enum.rst:637
525
679
msgid "The *start* parameter was added."
526
- msgstr ""
680
+ msgstr "新增了 *start* 參數。 "
527
681
528
682
#: ../../howto/enum.rst:642
529
683
msgid "Derived Enumerations"
530
- msgstr ""
684
+ msgstr "衍生列舉 "
531
685
532
686
#: ../../howto/enum.rst:645
533
687
msgid "IntEnum"
534
- msgstr ""
688
+ msgstr "IntEnum "
535
689
536
690
#: ../../howto/enum.rst:647
691
+ #, fuzzy
537
692
msgid ""
538
693
"The first variation of :class:`Enum` that is provided is also a subclass of :"
539
694
"class:`int`. Members of an :class:`IntEnum` can be compared to integers; by "
540
695
"extension, integer enumerations of different types can also be compared to "
541
696
"each other::"
542
697
msgstr ""
698
+ "提供的第一種:class:`Enum`變異體也是 :class:`int` 的子類別。:class:`IntEnum` "
699
+ "成員可與整數進行比較;由此,不同型別的整數列舉也可以相互比較: ::"
543
700
544
701
#: ../../howto/enum.rst:668
545
702
msgid ""
546
703
"However, they still can't be compared to standard :class:`Enum` "
547
704
"enumerations::"
548
- msgstr ""
705
+ msgstr "然而,它們仍無法與標準的 :class:`Enum` 型別相比較: :: "
549
706
550
707
#: ../../howto/enum.rst:681
551
708
msgid ""
552
709
":class:`IntEnum` values behave like integers in other ways you'd expect::"
553
- msgstr ""
710
+ msgstr ":class:`IntEnum` 型別的值在其他方面的行為就像你所預期的整數一樣: :: "
554
711
555
712
#: ../../howto/enum.rst:692
556
713
msgid "StrEnum"
557
- msgstr ""
714
+ msgstr "StrEnum "
558
715
559
716
#: ../../howto/enum.rst:694
717
+ #, fuzzy
560
718
msgid ""
561
719
"The second variation of :class:`Enum` that is provided is also a subclass "
562
720
"of :class:`str`. Members of a :class:`StrEnum` can be compared to strings; "
563
721
"by extension, string enumerations of different types can also be compared to "
564
722
"each other."
565
723
msgstr ""
724
+ "提供第二種 :class:`Enum` 變型的子類別 :class:`StrEnum`。:class:`StrEnum` 的成"
725
+ "員可與字串比較;因此,不同型態的字串列舉也可以彼此比較。"
566
726
567
727
#: ../../howto/enum.rst:703
568
728
msgid "IntFlag"
569
- msgstr ""
729
+ msgstr "IntFlag "
570
730
571
731
#: ../../howto/enum.rst:705
732
+ #, fuzzy
572
733
msgid ""
573
734
"The next variation of :class:`Enum` provided, :class:`IntFlag`, is also "
574
735
"based on :class:`int`. The difference being :class:`IntFlag` members can be "
@@ -577,61 +738,82 @@ msgid ""
577
738
"`IntFlag` members are also integers and can be used wherever an :class:`int` "
578
739
"is used."
579
740
msgstr ""
741
+ "提供的 Enum 的下一個變體 IntFlag 也基於 int。差別在於 IntFlag 成員可以使用位"
742
+ "元運算子(&、\\ |、^、~)進行組合,如果可能的話,結果仍然是 IntFlag 成員。與 "
743
+ "IntEnum 一樣,IntFlag 成員也是整數,並且可以在使用 int 的任何地方使用。"
580
744
581
745
#: ../../howto/enum.rst:713
746
+ #, fuzzy
582
747
msgid ""
583
748
"Any operation on an :class:`IntFlag` member besides the bit-wise operations "
584
749
"will lose the :class:`IntFlag` membership."
585
750
msgstr ""
751
+ "除了以位元運算的方式操作 :class:`IntFlag` 成員之外,其他任何操作都會使這個成"
752
+ "員失去屬於 :class:`IntFlag` 的身份。"
586
753
587
754
#: ../../howto/enum.rst:716
755
+ #, fuzzy
588
756
msgid ""
589
757
"Bit-wise operations that result in invalid :class:`IntFlag` values will lose "
590
758
"the :class:`IntFlag` membership. See :class:`FlagBoundary` for details."
591
759
msgstr ""
760
+ "進行位元運算,若導致 :class:`IntFlag` 值無效,就會失去 :class:`IntFlag` 成員"
761
+ "資格。詳細資訊請參考 :class:`FlagBoundary`。"
592
762
593
763
#: ../../howto/enum.rst:723
594
764
msgid "Sample :class:`IntFlag` class::"
595
- msgstr ""
765
+ msgstr "範例 :class:`IntFlag` 類別: :: "
596
766
597
767
#: ../../howto/enum.rst:739
598
768
msgid "It is also possible to name the combinations::"
599
- msgstr ""
769
+ msgstr "可以為這些組合命名: :: "
600
770
601
771
#: ../../howto/enum.rst:756
772
+ #, fuzzy
602
773
msgid ""
603
774
"Named combinations are considered aliases. Aliases do not show up during "
604
775
"iteration, but can be returned from by-value lookups."
605
776
msgstr ""
777
+ "已命名的組合被視為別名。\" Aliases\" 在疊代時不會顯示,但可以從按值查找中回"
778
+ "傳。"
606
779
607
780
#: ../../howto/enum.rst:761
781
+ #, fuzzy
608
782
msgid ""
609
783
"Another important difference between :class:`IntFlag` and :class:`Enum` is "
610
784
"that if no flags are set (the value is 0), its boolean evaluation is :data:"
611
785
"`False`::"
612
786
msgstr ""
787
+ ":class:`IntFlag` 和 :class:`Enum` 之間的另一個重要差異是,如果沒有設定旗標"
788
+ "(值為0),那麼它的布林估值就是 :data:`False`: ::"
613
789
614
790
#: ../../howto/enum.rst:769
791
+ #, fuzzy
615
792
msgid ""
616
793
"Because :class:`IntFlag` members are also subclasses of :class:`int` they "
617
794
"can be combined with them (but may lose :class:`IntFlag` membership::"
618
795
msgstr ""
796
+ "由於 :class:`IntFlag` 成員也是 :class:`int` 的子類別,因此它們可以與這些數值"
797
+ "結合使用 (但其可能失去 :class:`IntFlag` 的成員身份) : ::"
619
798
620
799
#: ../../howto/enum.rst:780
800
+ #, fuzzy
621
801
msgid ""
622
802
"The negation operator, ``~``, always returns an :class:`IntFlag` member with "
623
803
"a positive value::"
624
804
msgstr ""
805
+ "否定運算子 ``~``,總是會回傳一個 :class:`IntFlag` 成員,其值為正數: ::"
625
806
626
807
#: ../../howto/enum.rst:786
627
808
msgid ":class:`IntFlag` members can also be iterated over::"
628
- msgstr ""
809
+ msgstr ":class:`IntFlag` 的成員也可以進行疊代: :: "
629
810
630
811
#: ../../howto/enum.rst:795
631
812
msgid "Flag"
632
- msgstr ""
813
+ msgstr "Flag "
633
814
634
815
#: ../../howto/enum.rst:797
816
+ #, fuzzy
635
817
msgid ""
636
818
"The last variation is :class:`Flag`. Like :class:`IntFlag`, :class:`Flag` "
637
819
"members can be combined using the bitwise operators (&, \\ |, ^, ~). Unlike :"
@@ -640,30 +822,41 @@ msgid ""
640
822
"specify the values directly it is recommended to use :class:`auto` as the "
641
823
"value and let :class:`Flag` select an appropriate value."
642
824
msgstr ""
825
+ "最後一個變體是 Flag。與 IntFlag 一樣,Flag 成員可以使用位元運算子(&、\\ |、"
826
+ "^、~)進行組合。與 IntFlag 不同,它們不能與任何其他 Flag 列舉或 int 組合或比"
827
+ "較。雖然可以直接指定值,但建議使用 auto 作為值,並讓 Flag 選擇適當的值。"
643
828
644
829
#: ../../howto/enum.rst:806
830
+ #, fuzzy
645
831
msgid ""
646
832
"Like :class:`IntFlag`, if a combination of :class:`Flag` members results in "
647
833
"no flags being set, the boolean evaluation is :data:`False`::"
648
834
msgstr ""
835
+ "類似 :class:`IntFlag` 的作法,如果一組 :class:`Flag` 類別的成員結果沒有任何旗"
836
+ "標被設定,那麼布林式評估會是 :data:`False`: ::"
649
837
650
838
#: ../../howto/enum.rst:820
839
+ #, fuzzy
651
840
msgid ""
652
841
"Individual flags should have values that are powers of two (1, 2, 4, "
653
842
"8, ...), while combinations of flags will not::"
654
843
msgstr ""
844
+ "個別的旗標 (flag) 應該具有 2 的次方數值 (1, 2, 4, 8...),而旗標組合則不"
845
+ "會: ::"
655
846
656
847
#: ../../howto/enum.rst:832
848
+ #, fuzzy
657
849
msgid ""
658
850
"Giving a name to the \" no flags set\" condition does not change its boolean "
659
851
"value::"
660
- msgstr ""
852
+ msgstr "將「無旗標設置」狀況命名並不會改變其布林值: "
661
853
662
854
#: ../../howto/enum.rst:846
663
855
msgid ":class:`Flag` members can also be iterated over::"
664
- msgstr ""
856
+ msgstr ":class:`Flag` 成員也可以被疊代: :: "
665
857
666
858
#: ../../howto/enum.rst:856
859
+ #, fuzzy
667
860
msgid ""
668
861
"For the majority of new code, :class:`Enum` and :class:`Flag` are strongly "
669
862
"recommended, since :class:`IntEnum` and :class:`IntFlag` break some semantic "
@@ -673,176 +866,240 @@ msgid ""
673
866
"will not do; for example, when integer constants are replaced with "
674
867
"enumerations, or for interoperability with other systems."
675
868
msgstr ""
869
+ "對於大部分的新程式碼,強烈建議使用 :class:`Enum` 和 :class:`Flag`, 因為 :"
870
+ "class:`IntEnum` 和 :class:`IntFlag` 違反了列舉型別的一些語意承諾(可比較整數,"
871
+ "因此也可適用於其他無關聯的列舉型別)。只有在不具備:class: `Enum`和:class: "
872
+ "`Flag` 的功能時方才應使用:class: ` IntEnum`與: class:``IntDate``;例如當整"
873
+ "數常量被替換成列舉常量或需要互通性質上其他系統時。"
676
874
677
875
#: ../../howto/enum.rst:866
678
876
msgid "Others"
679
- msgstr ""
877
+ msgstr "其他 "
680
878
681
879
#: ../../howto/enum.rst:868
880
+ #, fuzzy
682
881
msgid ""
683
882
"While :class:`IntEnum` is part of the :mod:`enum` module, it would be very "
684
883
"simple to implement independently::"
685
884
msgstr ""
885
+ "雖然 :class:`IntEnum` 是 :mod:`enum` 模組的一部分,但獨立實現也非常簡單: ::"
686
886
687
887
#: ../../howto/enum.rst:874
888
+ #, fuzzy
688
889
msgid ""
689
890
"This demonstrates how similar derived enumerations can be defined; for "
690
891
"example a :class:`FloatEnum` that mixes in :class:`float` instead of :class:"
691
892
"`int`."
692
893
msgstr ""
894
+ "這展示了多種派生列舉定義相似之處;例如,一個以浮點型別(``float``)混入代替整"
895
+ "數(``int``)的 ``FloatEnum`` 類別。"
693
896
694
897
#: ../../howto/enum.rst:877
695
898
msgid "Some rules:"
696
- msgstr ""
899
+ msgstr "一些規則: "
697
900
698
901
#: ../../howto/enum.rst:879
902
+ #, fuzzy
699
903
msgid ""
700
904
"When subclassing :class:`Enum`, mix-in types must appear before :class:"
701
905
"`Enum` itself in the sequence of bases, as in the :class:`IntEnum` example "
702
906
"above."
703
907
msgstr ""
908
+ "當子類別化 :class:`Enum` 時,mix-in 的型別必須在 :class:`Enum` 本身之前出現於"
909
+ "基礎序列中,就像先前舉的 :class:`IntEnum` 範例。"
704
910
705
911
#: ../../howto/enum.rst:882
912
+ #, fuzzy
706
913
msgid ""
707
914
"Mix-in types must be subclassable. For example, :class:`bool` and :class:"
708
915
"`range` are not subclassable and will throw an error during Enum creation if "
709
916
"used as the mix-in type."
710
917
msgstr ""
918
+ "混入類別必須是可被繼承的。例如 :class:`bool` 和 :class:`range` 並非可被子類化"
919
+ "的,如果用於作為混入類型則會在建立列舉時拋出錯誤訊息。"
711
920
712
921
#: ../../howto/enum.rst:885
922
+ #, fuzzy
713
923
msgid ""
714
924
"While :class:`Enum` can have members of any type, once you mix in an "
715
925
"additional type, all the members must have values of that type, e.g. :class:"
716
926
"`int` above. This restriction does not apply to mix-ins which only add "
717
927
"methods and don't specify another type."
718
928
msgstr ""
929
+ "雖然:class:`Enum`可以包含任何型別的成員,但是一旦混合了其他型別,所有的成員都"
930
+ "必須具有該型別的值,例如上面提到的 :class:`int`。這個限制不適用於僅添加方法而"
931
+ "未指定另一種類型的 mixin。"
719
932
720
933
#: ../../howto/enum.rst:889
934
+ #, fuzzy
721
935
msgid ""
722
936
"When another data type is mixed in, the :attr:`value` attribute is *not the "
723
937
"same* as the enum member itself, although it is equivalent and will compare "
724
938
"equal."
725
939
msgstr ""
940
+ "當enum與其他型別混在一起時,即使他們是相等的且具有可比性,該列舉成員本身和屬"
941
+ "性 :attr:`value` *不會完全相同*。"
726
942
727
943
#: ../../howto/enum.rst:892
944
+ #, fuzzy
728
945
msgid ""
729
946
"A ``data type`` is a mixin that defines :meth:`__new__`, or a :class:"
730
947
"`~dataclasses.dataclass`"
731
948
msgstr ""
949
+ "``data type`` 是定義 :meth:`__new__` 或 :class:`~dataclasses.dataclass` 的 "
950
+ "mixin"
732
951
733
952
#: ../../howto/enum.rst:894
953
+ #, fuzzy
734
954
msgid ""
735
955
"%-style formatting: ``%s`` and ``%r`` call the :class:`Enum` class's :meth:"
736
956
"`__str__` and :meth:`__repr__` respectively; other codes (such as ``%i`` or "
737
957
"``%h`` for IntEnum) treat the enum member as its mixed-in type."
738
958
msgstr ""
959
+ "% 風格的格式化:使用 ``%s`` 和 ``%r``,分別會呼叫 :class:`Enum` 類別的 :meth:"
960
+ "`__str__` 和 :meth:`__repr__`;其它格式符號(例如:IntEnum 的 ``%i`` 或 "
961
+ "``%h``)則將列舉成員視為其混入型別。"
739
962
740
963
#: ../../howto/enum.rst:897
741
964
msgid ""
742
965
":ref:`Formatted string literals <f-strings>`, :meth:`str.format`, and :func:"
743
966
"`format` will use the enum's :meth:`__str__` method."
744
967
msgstr ""
968
+ ":ref:`格式化字串文本 <f-strings>`、:meth:`str.format` 和 :func:`format` 會使"
969
+ "用列舉的 :meth:`__str__` 方法。"
745
970
746
971
#: ../../howto/enum.rst:902
972
+ #, fuzzy
747
973
msgid ""
748
974
"Because :class:`IntEnum`, :class:`IntFlag`, and :class:`StrEnum` are "
749
975
"designed to be drop-in replacements for existing constants, their :meth:"
750
976
"`__str__` method has been reset to their data types' :meth:`__str__` method."
751
977
msgstr ""
978
+ "由於 :class:`IntEnum`、:class:`IntFlag` 和 :class:`StrEnum` 被設計為現有常數"
979
+ "的即插即用替代品,因此它們的 :meth:`__str__` 方法已被重置為其資料類型的 :"
980
+ "meth:`__str__` 方法。"
752
981
753
982
#: ../../howto/enum.rst:910
754
983
msgid "When to use :meth:`__new__` vs. :meth:`__init__`"
755
- msgstr ""
984
+ msgstr "何時使用 :meth:`__new__` 而不是 :meth:`__init__` "
756
985
757
986
#: ../../howto/enum.rst:912
987
+ #, fuzzy
758
988
msgid ""
759
989
":meth:`__new__` must be used whenever you want to customize the actual value "
760
990
"of the :class:`Enum` member. Any other modifications may go in either :meth:"
761
991
"`__new__` or :meth:`__init__`, with :meth:`__init__` being preferred."
762
992
msgstr ""
993
+ "當你想客製化 :class:`Enum` 成員的實際值時,必須使用 :meth:`__new__`。任何其他"
994
+ "修改可以放在 :meth:`__new_` 或是 :meth:`__init__` 中,而優先選擇使用 :meth:"
995
+ "`__init__ ` 進行修改。"
763
996
764
997
#: ../../howto/enum.rst:916
998
+ #, fuzzy
765
999
msgid ""
766
1000
"For example, if you want to pass several items to the constructor, but only "
767
1001
"want one of them to be the value::"
768
- msgstr ""
1002
+ msgstr "例如,如果你想傳遞幾個項目給構造函式,但只想其中一個是值: :: "
769
1003
770
1004
#: ../../howto/enum.rst:943
1005
+ #, fuzzy
771
1006
msgid ""
772
1007
"*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the "
773
1008
"one that is found; instead, use the data type directly."
774
1009
msgstr ""
1010
+ "*不要*呼叫 ``super().__new__()``,因為只查找 ``__new__`` 是找到的;相反,直接"
1011
+ "使用資料型態。"
775
1012
776
1013
#: ../../howto/enum.rst:948
1014
+ #, fuzzy
777
1015
msgid "Finer Points"
778
- msgstr ""
1016
+ msgstr "微妙之處 "
779
1017
780
1018
#: ../../howto/enum.rst:951
781
1019
msgid "Supported ``__dunder__`` names"
782
- msgstr ""
1020
+ msgstr "有支援的 ``__dunder_ _`` 命名 "
783
1021
784
1022
#: ../../howto/enum.rst:953
1023
+ #, fuzzy
785
1024
msgid ""
786
1025
":attr:`__members__` is a read-only ordered mapping of ``member_name``:"
787
1026
"``member`` items. It is only available on the class."
788
1027
msgstr ""
1028
+ ":attr:`__members__` 是一個唯讀的有序映射,包含了 ``member_name``:``member`` "
1029
+ "項目,在類別中才能使用。"
789
1030
790
1031
#: ../../howto/enum.rst:956
1032
+ #, fuzzy
791
1033
msgid ""
792
1034
":meth:`__new__`, if specified, must create and return the enum members; it "
793
1035
"is also a very good idea to set the member's :attr:`_value_` appropriately. "
794
1036
"Once all the members are created it is no longer used."
795
1037
msgstr ""
1038
+ "如果指定了 `:meth:`__new__`` 則必須建立並回傳列舉成員;同時,為其 :attr:"
1039
+ "`_value_` 正確設值是一個非常好的選擇。當所有成員都建立完成後,此方法將不再使"
1040
+ "用。"
796
1041
797
1042
#: ../../howto/enum.rst:962
798
1043
msgid "Supported ``_sunder_`` names"
799
- msgstr ""
1044
+ msgstr "有支援的 ``_sunder_`` 命名 "
800
1045
801
1046
#: ../../howto/enum.rst:964
802
1047
msgid "``_name_`` -- name of the member"
803
- msgstr ""
1048
+ msgstr "``_name_`` -- 成員的名稱 "
804
1049
805
1050
#: ../../howto/enum.rst:965
806
1051
msgid ""
807
1052
"``_value_`` -- value of the member; can be set / modified in ``__new__``"
808
- msgstr ""
1053
+ msgstr "``_value_`` -- 成員的值;可在 ``__new__`` 中設定/修改 "
809
1054
810
1055
#: ../../howto/enum.rst:967
811
1056
msgid ""
812
1057
"``_missing_`` -- a lookup function used when a value is not found; may be "
813
1058
"overridden"
814
- msgstr ""
1059
+ msgstr "``_missing_`` -- 當找不到值時使用的查詢函式;可以被覆寫 "
815
1060
816
1061
#: ../../howto/enum.rst:969
1062
+ #, fuzzy
817
1063
msgid ""
818
1064
"``_ignore_`` -- a list of names, either as a :class:`list` or a :class:"
819
1065
"`str`, that will not be transformed into members, and will be removed from "
820
1066
"the final class"
821
1067
msgstr ""
1068
+ "``_ignore_`` -- 包含不需要作為類別成員的名稱的列表,必須是 :class:`list` 或 :"
1069
+ "class:`str` 類型,這些名稱將不會轉換為類別成員且將從最終所建立的類別中移除"
822
1070
823
1071
#: ../../howto/enum.rst:972
1072
+ #, fuzzy
824
1073
msgid ""
825
1074
"``_order_`` -- used in Python 2/3 code to ensure member order is consistent "
826
1075
"(class attribute, removed during class creation)"
827
1076
msgstr ""
1077
+ "``_order_`` -- 在 Python 2/3 程式碼中使用以確保成員順序一致(類屬性,在類建立"
1078
+ "期間刪除)"
828
1079
829
1080
#: ../../howto/enum.rst:974
1081
+ #, fuzzy
830
1082
msgid ""
831
1083
"``_generate_next_value_`` -- used by the `Functional API`_ and by :class:"
832
1084
"`auto` to get an appropriate value for an enum member; may be overridden"
833
1085
msgstr ""
1086
+ "``_generate_next_value_`` 是供 `Functional API`_ 和 :class:`auto` 使用的方"
1087
+ "法,以便取得適當的列舉成員值;可被覆寫。"
834
1088
835
1089
#: ../../howto/enum.rst:980
836
1090
msgid ""
837
1091
"For standard :class:`Enum` classes the next value chosen is the last value "
838
1092
"seen incremented by one."
839
- msgstr ""
1093
+ msgstr "對於標準的 :class:`Enum` 類別,下一個選擇的值是最後看到的值加一。 "
840
1094
841
1095
#: ../../howto/enum.rst:983
1096
+ #, fuzzy
842
1097
msgid ""
843
1098
"For :class:`Flag` classes the next value chosen will be the next highest "
844
1099
"power-of-two, regardless of the last value seen."
845
1100
msgstr ""
1101
+ "對於 :class:`Flag` 類別,下一個被選擇的值是接下來最高的二次冪,無論上一個值是"
1102
+ "否見過。"
846
1103
847
1104
#: ../../howto/enum.rst:986
848
1105
msgid "``_missing_``, ``_order_``, ``_generate_next_value_``"
@@ -853,33 +1110,42 @@ msgid "``_ignore_``"
853
1110
msgstr "``_ignore_``"
854
1111
855
1112
#: ../../howto/enum.rst:989
1113
+ #, fuzzy
856
1114
msgid ""
857
1115
"To help keep Python 2 / Python 3 code in sync an :attr:`_order_` attribute "
858
1116
"can be provided. It will be checked against the actual order of the "
859
1117
"enumeration and raise an error if the two do not match::"
860
1118
msgstr ""
1119
+ "為了協助保持 Python 2 / Python 3 的程式碼同步,可以提供一個 :attr:`_order_` "
1120
+ "屬性。它將與列舉的實際順序進行檢查,如果不符則會引發錯誤: ::"
861
1121
862
1122
#: ../../howto/enum.rst:1007
863
1123
msgid ""
864
1124
"In Python 2 code the :attr:`_order_` attribute is necessary as definition "
865
1125
"order is lost before it can be recorded."
866
1126
msgstr ""
1127
+ "在 Python 2 的程式中,:attr:`_order_` 屬性是必要的,因為定義順序在記錄之前就"
1128
+ "已遺失。"
867
1129
868
1130
#: ../../howto/enum.rst:1012
869
1131
msgid "_Private__names"
870
- msgstr ""
1132
+ msgstr "_Private__names "
871
1133
872
1134
#: ../../howto/enum.rst:1014
1135
+ #, fuzzy
873
1136
msgid ""
874
1137
":ref:`Private names <private-name-mangling>` are not converted to enum "
875
1138
"members, but remain normal attributes."
876
1139
msgstr ""
1140
+ "私有名稱(即雙下劃線開頭的屬性或方法)不會轉換成列舉成員,而是保持正常屬性。"
1141
+ "請參見 :ref:`Private names <private-name-mangling>`。"
877
1142
878
1143
#: ../../howto/enum.rst:1021
879
1144
msgid "``Enum`` member type"
880
- msgstr ""
1145
+ msgstr "``Enum`` 成員型別 "
881
1146
882
1147
#: ../../howto/enum.rst:1023
1148
+ #, fuzzy
883
1149
msgid ""
884
1150
"Enum members are instances of their enum class, and are normally accessed as "
885
1151
"``EnumClass.member``. In certain situations, such as writing custom enum "
@@ -888,162 +1154,198 @@ msgid ""
888
1154
"names and attributes/methods from mixed-in classes, upper-case names are "
889
1155
"strongly recommended."
890
1156
msgstr ""
1157
+ "列舉成員是其列舉類別的實例,通常會以 ``EnumClass.member`` 來存取。在某些情況"
1158
+ "下,例如編寫自訂列舉行為,能夠直接從另一個成員存取一個成員是有用的,並且受到"
1159
+ "支援;但是,為了避免混合類別中的成員名稱和屬性/方法之間的名稱衝突,強烈建議使"
1160
+ "用大寫名稱。"
891
1161
892
1162
#: ../../howto/enum.rst:1034
893
1163
msgid "Creating members that are mixed with other data types"
894
- msgstr ""
1164
+ msgstr "建立和其他資料型別混合的成員 "
895
1165
896
1166
#: ../../howto/enum.rst:1036
1167
+ #, fuzzy
897
1168
msgid ""
898
1169
"When subclassing other data types, such as :class:`int` or :class:`str`, "
899
1170
"with an :class:`Enum`, all values after the ``=`` are passed to that data "
900
1171
"type's constructor. For example::"
901
1172
msgstr ""
1173
+ "當需要對其他數據類型(例如 :class:`int` 或 :class:`str`)進行父類別派生並使用"
1174
+ "到:class:`Enum`時,屬於 `=` 之後的所有值都會傳遞給該數據類型的建構函式。例"
1175
+ "如: ::"
902
1176
903
1177
#: ../../howto/enum.rst:1048
904
1178
msgid "Boolean value of ``Enum`` classes and members"
905
- msgstr ""
1179
+ msgstr "``Enum`` 類別和成員的布林值 "
906
1180
907
1181
#: ../../howto/enum.rst:1050
1182
+ #, fuzzy
908
1183
msgid ""
909
1184
"Enum classes that are mixed with non-:class:`Enum` types (such as :class:"
910
1185
"`int`, :class:`str`, etc.) are evaluated according to the mixed-in type's "
911
1186
"rules; otherwise, all members evaluate as :data:`True`. To make your own "
912
1187
"enum's boolean evaluation depend on the member's value add the following to "
913
1188
"your class::"
914
1189
msgstr ""
1190
+ "混合了非 :class:`Enum` 型別(例如:class:`int`、:class:`str`等)的列舉類型,會"
1191
+ "依據混入型別所規定的規則進行評估;否則,所有成員均評估為:data: `True`. 要讓你"
1192
+ "自己的enum布林求值取決於成員值時,在你的類中添加以下內容: ::"
915
1193
916
1194
#: ../../howto/enum.rst:1059
917
1195
msgid "Plain :class:`Enum` classes always evaluate as :data:`True`."
918
- msgstr ""
1196
+ msgstr "通常 :class:`Enum` 類別的值會被計算為 :data:`True`。 "
919
1197
920
1198
#: ../../howto/enum.rst:1063
921
1199
msgid "``Enum`` classes with methods"
922
- msgstr ""
1200
+ msgstr "具有方法的 ``Enum`` 類別 "
923
1201
924
1202
#: ../../howto/enum.rst:1065
1203
+ #, fuzzy
925
1204
msgid ""
926
1205
"If you give your enum subclass extra methods, like the `Planet`_ class "
927
1206
"below, those methods will show up in a :func:`dir` of the member, but not of "
928
1207
"the class::"
929
1208
msgstr ""
1209
+ "如果你給你的列舉子類別新增了一些方法,就像下面這個 `Planet`_ 類別,那這些方法"
1210
+ "會出現在成員的 :func:`dir`,但不會出現在列舉本身的 :func:`dir` 裡: ::"
930
1211
931
1212
#: ../../howto/enum.rst:1076
932
1213
msgid "Combining members of ``Flag``"
933
- msgstr ""
1214
+ msgstr "合併 ``Flag`` 的成員 "
934
1215
935
1216
#: ../../howto/enum.rst:1078
1217
+ #, fuzzy
936
1218
msgid ""
937
1219
"Iterating over a combination of :class:`Flag` members will only return the "
938
1220
"members that are comprised of a single bit::"
939
- msgstr ""
1221
+ msgstr "疊代 :class:`Flag` 成員的組合將只會回傳由單一位元所構成的成員: :: "
940
1222
941
1223
#: ../../howto/enum.rst:1096
1224
+ #, fuzzy
942
1225
msgid "``Flag`` and ``IntFlag`` minutia"
943
- msgstr ""
1226
+ msgstr "``Flag`` 和 ``IntFlag`` 細節部份 "
944
1227
945
1228
#: ../../howto/enum.rst:1098
946
1229
msgid "Using the following snippet for our examples::"
947
- msgstr ""
1230
+ msgstr "我們將運用下列程式碼片段作為範例: :: "
948
1231
949
1232
#: ../../howto/enum.rst:1109
950
1233
msgid "the following are true:"
951
- msgstr ""
1234
+ msgstr "以下敘述為真: "
952
1235
953
1236
#: ../../howto/enum.rst:1111
1237
+ #, fuzzy
954
1238
msgid "single-bit flags are canonical"
955
- msgstr ""
1239
+ msgstr "單位元旗標是規範的 "
956
1240
957
1241
#: ../../howto/enum.rst:1112
958
1242
msgid "multi-bit and zero-bit flags are aliases"
959
- msgstr ""
1243
+ msgstr "多位元旗標和零位元旗標是別名 "
960
1244
961
1245
#: ../../howto/enum.rst:1113
1246
+ #, fuzzy
962
1247
msgid "only canonical flags are returned during iteration::"
963
- msgstr ""
1248
+ msgstr "疊代時只回傳正規旗標 (canonical flags): :: "
964
1249
965
1250
#: ../../howto/enum.rst:1118
1251
+ #, fuzzy
966
1252
msgid ""
967
1253
"negating a flag or flag set returns a new flag/flag set with the "
968
1254
"corresponding positive integer value::"
969
- msgstr ""
1255
+ msgstr "否定一個旗標或旗標集會回傳對應的正整數值: :: "
970
1256
971
1257
#: ../../howto/enum.rst:1127
1258
+ #, fuzzy
972
1259
msgid "names of pseudo-flags are constructed from their members' names::"
973
- msgstr ""
1260
+ msgstr "偽旗標的名稱是由其成員名稱建構而成的: :: "
974
1261
975
1262
#: ../../howto/enum.rst:1132
976
1263
msgid "multi-bit flags, aka aliases, can be returned from operations::"
977
- msgstr ""
1264
+ msgstr "多位元旗標,也就是別名,可以從操作中回傳: :: "
978
1265
979
1266
#: ../../howto/enum.rst:1143
1267
+ #, fuzzy
980
1268
msgid ""
981
1269
"membership / containment checking: zero-valued flags are always considered "
982
1270
"to be contained::"
983
- msgstr ""
1271
+ msgstr "成員 / 包含測試:零值旗標始終被認為是包含的: :: "
984
1272
985
1273
#: ../../howto/enum.rst:1149
1274
+ #, fuzzy
986
1275
msgid ""
987
1276
"otherwise, only if all bits of one flag are in the other flag will True be "
988
1277
"returned::"
989
- msgstr ""
1278
+ msgstr "否則,只有當一個旗標的所有位都在另一個旗標中時,才會回傳 True: :: "
990
1279
991
1280
#: ../../howto/enum.rst:1158
1281
+ #, fuzzy
992
1282
msgid ""
993
1283
"There is a new boundary mechanism that controls how out-of-range / invalid "
994
1284
"bits are handled: ``STRICT``, ``CONFORM``, ``EJECT``, and ``KEEP``:"
995
1285
msgstr ""
1286
+ "有一個新的邊界機制控制超出範圍或無效位元的處理方式: ``STRICT``(嚴格)、"
1287
+ "``CONFORM``(遵從)、``EJECT``(彈出)和 ``KEEP``(保留):"
996
1288
997
1289
#: ../../howto/enum.rst:1161
1290
+ #, fuzzy
998
1291
msgid "STRICT --> raises an exception when presented with invalid values"
999
- msgstr ""
1292
+ msgstr "在遇到無效數值時,STRICT(嚴格模式)會引發一個異常。 "
1000
1293
1001
1294
#: ../../howto/enum.rst:1162
1002
1295
msgid "CONFORM --> discards any invalid bits"
1003
- msgstr ""
1296
+ msgstr "CONFORM --> 丟棄任何無效的位元 "
1004
1297
1005
1298
#: ../../howto/enum.rst:1163
1299
+ #, fuzzy
1006
1300
msgid "EJECT --> lose Flag status and become a normal int with the given value"
1007
- msgstr ""
1301
+ msgstr "EJECT --> 失去旗標狀態,並成為一個具有給定值的普通整數 "
1008
1302
1009
1303
#: ../../howto/enum.rst:1164
1010
1304
msgid "KEEP --> keep the extra bits"
1011
- msgstr ""
1305
+ msgstr "KEEP --> 保留額外的位元 "
1012
1306
1013
1307
#: ../../howto/enum.rst:1166
1014
1308
msgid "keeps Flag status and extra bits"
1015
- msgstr ""
1309
+ msgstr "保留旗標狀態和額外位元 "
1016
1310
1017
1311
#: ../../howto/enum.rst:1167
1018
1312
msgid "extra bits do not show up in iteration"
1019
- msgstr ""
1313
+ msgstr "額外位元在疊代時不會出現 "
1020
1314
1021
1315
#: ../../howto/enum.rst:1168
1022
1316
msgid "extra bits do show up in repr() and str()"
1023
- msgstr ""
1317
+ msgstr "在 repr() 和 str() 也會顯示額外的位元 "
1024
1318
1025
1319
#: ../../howto/enum.rst:1170
1320
+ #, fuzzy
1026
1321
msgid ""
1027
1322
"The default for Flag is ``STRICT``, the default for ``IntFlag`` is "
1028
1323
"``EJECT``, and the default for ``_convert_`` is ``KEEP`` (see ``ssl."
1029
1324
"Options`` for an example of when ``KEEP`` is needed)."
1030
1325
msgstr ""
1326
+ "標記的預設值為「嚴格」(``STRICT``),IntFlag 的預設值為「拋出異常」"
1327
+ "(``EJECT``),而 _convert_ 的預設值則是「保持現況」(``KEEP``) (請參考 ``ssl."
1328
+ "Options`` 中需要使用 ``KEEP`` 的範例)。"
1031
1329
1032
1330
#: ../../howto/enum.rst:1178
1033
1331
msgid "How are Enums and Flags different?"
1034
- msgstr ""
1332
+ msgstr "列舉和旗標有何不同? "
1035
1333
1036
1334
#: ../../howto/enum.rst:1180
1335
+ #, fuzzy
1037
1336
msgid ""
1038
1337
"Enums have a custom metaclass that affects many aspects of both derived :"
1039
1338
"class:`Enum` classes and their instances (members)."
1040
1339
msgstr ""
1340
+ "限定列舉 (Enums) 有一個獨特的元類,會影響到所有衍生 :class:`Enum` 類別及其實"
1341
+ "例(成員)的許多屬性。"
1041
1342
1042
1343
#: ../../howto/enum.rst:1185
1043
1344
msgid "Enum Classes"
1044
- msgstr ""
1345
+ msgstr "列舉類別 "
1045
1346
1046
1347
#: ../../howto/enum.rst:1187
1348
+ #, fuzzy
1047
1349
msgid ""
1048
1350
"The :class:`EnumType` metaclass is responsible for providing the :meth:"
1049
1351
"`__contains__`, :meth:`__dir__`, :meth:`__iter__` and other methods that "
@@ -1053,222 +1355,271 @@ msgid ""
1053
1355
"final :class:`Enum` class are correct (such as :meth:`__new__`, :meth:"
1054
1356
"`__getnewargs__`, :meth:`__str__` and :meth:`__repr__`)."
1055
1357
msgstr ""
1358
+ ":class:`EnumType`(列舉型別) 元類別(meta-class) 負責提供 `__contains__`、 "
1359
+ "`__dir__`、 `__iter__` 以及其他方法,允許開發人員使用像是 ``list(Color)`` 或"
1360
+ "是 ``some_enum_var in Color`` 的方式對一個 :class:`Enum`(列舉類別)進行操作,"
1361
+ "而通常類別則無法進行。:class:`EnumType`維護被命名的常數(names constants),例"
1362
+ "如 :meth:`__new__.`, :meth:`__getnewargs__.`, :meth:`__str__.`, 和:meth: "
1363
+ "'__repr__',並確保最終的:class'Enum'(列舉class)符合指定格式。"
1056
1364
1057
1365
#: ../../howto/enum.rst:1196
1058
1366
msgid "Flag Classes"
1059
- msgstr ""
1367
+ msgstr "旗標類別 "
1060
1368
1061
1369
#: ../../howto/enum.rst:1198
1370
+ #, fuzzy
1062
1371
msgid ""
1063
1372
"Flags have an expanded view of aliasing: to be canonical, the value of a "
1064
1373
"flag needs to be a power-of-two value, and not a duplicate name. So, in "
1065
1374
"addition to the :class:`Enum` definition of alias, a flag with no value (a.k."
1066
1375
"a. ``0``) or with more than one power-of-two value (e.g. ``3``) is "
1067
1376
"considered an alias."
1068
1377
msgstr ""
1378
+ "旗標有一個更廣泛的別名觀點:為了符合規範,旗標的值需要是二次冪的值,而不是重"
1379
+ "複的名稱。因此除了使用 :class:`Enum` 別名定義之外,沒有值(a.k.a. `0`)或多於"
1380
+ "一個二次冪數(例如 `3`)的旗幟也被視為別名。"
1069
1381
1070
1382
#: ../../howto/enum.rst:1204
1071
1383
msgid "Enum Members (aka instances)"
1072
- msgstr ""
1384
+ msgstr "列舉成員(又稱為實例) "
1073
1385
1074
1386
#: ../../howto/enum.rst:1206
1387
+ #, fuzzy
1075
1388
msgid ""
1076
1389
"The most interesting thing about enum members is that they are singletons. :"
1077
1390
"class:`EnumType` creates them all while it is creating the enum class "
1078
1391
"itself, and then puts a custom :meth:`__new__` in place to ensure that no "
1079
1392
"new ones are ever instantiated by returning only the existing member "
1080
1393
"instances."
1081
1394
msgstr ""
1395
+ "enum 成員最有趣的地方在於它們是單例 (singletons)。當 :class:`EnumType` 建立列"
1396
+ "舉類別本身時,就會一併建立這些成員,並提供自訂的 :meth:`__new__` 方法來確保只"
1397
+ "回傳現有的成員實例,而不會再被實體化出新的。"
1082
1398
1083
1399
#: ../../howto/enum.rst:1212
1084
1400
msgid "Flag Members"
1085
- msgstr ""
1401
+ msgstr "旗標成員 "
1086
1402
1087
1403
#: ../../howto/enum.rst:1214
1404
+ #, fuzzy
1088
1405
msgid ""
1089
1406
"Flag members can be iterated over just like the :class:`Flag` class, and "
1090
1407
"only the canonical members will be returned. For example::"
1091
1408
msgstr ""
1409
+ "旗標成員可像 :class:`Flag` 類別一樣被疊代,只有典型成員會被回傳。舉例而"
1410
+ "言: ::"
1092
1411
1093
1412
#: ../../howto/enum.rst:1220
1094
1413
msgid "(Note that ``BLACK``, ``PURPLE``, and ``WHITE`` do not show up.)"
1095
- msgstr ""
1414
+ msgstr "(請注意,``BLACK``、``PURPLE`` 和 ``WHITE`` 不會出現) "
1096
1415
1097
1416
#: ../../howto/enum.rst:1222
1098
1417
msgid ""
1099
1418
"Inverting a flag member returns the corresponding positive value, rather "
1100
1419
"than a negative value --- for example::"
1101
- msgstr ""
1420
+ msgstr "反轉旗標成員會回傳相應的正值,而不是負值 --- 例如: :: "
1102
1421
1103
1422
#: ../../howto/enum.rst:1228
1423
+ #, fuzzy
1104
1424
msgid ""
1105
1425
"Flag members have a length corresponding to the number of power-of-two "
1106
1426
"values they contain. For example::"
1107
- msgstr ""
1427
+ msgstr "旗標成員的長度與他們包含的二次冥值相對應。例如: :: "
1108
1428
1109
1429
#: ../../howto/enum.rst:1238
1110
1430
msgid "Enum Cookbook"
1111
- msgstr ""
1431
+ msgstr "列舉參考手冊 "
1112
1432
1113
1433
#: ../../howto/enum.rst:1241
1434
+ #, fuzzy
1114
1435
msgid ""
1115
1436
"While :class:`Enum`, :class:`IntEnum`, :class:`StrEnum`, :class:`Flag`, and :"
1116
1437
"class:`IntFlag` are expected to cover the majority of use-cases, they cannot "
1117
1438
"cover them all. Here are recipes for some different types of enumerations "
1118
1439
"that can be used directly, or as examples for creating one's own."
1119
- msgstr ""
1440
+ msgstr "雖然我們期望 :class:`Enum`、:cl "
1120
1441
1121
1442
#: ../../howto/enum.rst:1248
1122
1443
msgid "Omitting values"
1123
- msgstr ""
1444
+ msgstr "省略值 "
1124
1445
1125
1446
#: ../../howto/enum.rst:1250
1126
1447
msgid ""
1127
1448
"In many use-cases, one doesn't care what the actual value of an enumeration "
1128
1449
"is. There are several ways to define this type of simple enumeration:"
1129
- msgstr ""
1450
+ msgstr "很多時候,我們不在意列舉的實際值。定義這種簡單的列舉有幾種方式: "
1130
1451
1131
1452
#: ../../howto/enum.rst:1253
1132
1453
msgid "use instances of :class:`auto` for the value"
1133
- msgstr ""
1454
+ msgstr "使用 :class:`auto` 的實例當作值 "
1134
1455
1135
1456
#: ../../howto/enum.rst:1254
1136
1457
msgid "use instances of :class:`object` as the value"
1137
- msgstr ""
1458
+ msgstr "使用 :class:`object` 的實例作為值。 "
1138
1459
1139
1460
#: ../../howto/enum.rst:1255
1140
1461
msgid "use a descriptive string as the value"
1141
- msgstr ""
1462
+ msgstr "使用描述性的字串作為值 "
1142
1463
1143
1464
#: ../../howto/enum.rst:1256
1465
+ #, fuzzy
1144
1466
msgid ""
1145
1467
"use a tuple as the value and a custom :meth:`__new__` to replace the tuple "
1146
1468
"with an :class:`int` value"
1147
1469
msgstr ""
1470
+ "使用元組作為值,再加上自定義的 :meth:`__new__` 函式來將該元組替換成 :class:"
1471
+ "`int` 型別的值"
1148
1472
1149
1473
#: ../../howto/enum.rst:1259
1474
+ #, fuzzy
1150
1475
msgid ""
1151
1476
"Using any of these methods signifies to the user that these values are not "
1152
1477
"important, and also enables one to add, remove, or reorder members without "
1153
1478
"having to renumber the remaining members."
1154
1479
msgstr ""
1480
+ "使用這些方法之一,向使用者傳達數值不重要的意涵,也能讓你加入、移除或重新排序"
1481
+ "成員而不必重新編號其他成員。"
1155
1482
1156
1483
#: ../../howto/enum.rst:1265
1157
1484
msgid "Using :class:`auto`"
1158
- msgstr ""
1485
+ msgstr "使用 :class:`auto` "
1159
1486
1160
1487
#: ../../howto/enum.rst:1267
1161
1488
msgid "Using :class:`auto` would look like::"
1162
- msgstr ""
1489
+ msgstr "使用 :class:`auto` 看起來會像這樣: :: "
1163
1490
1164
1491
#: ../../howto/enum.rst:1279
1165
1492
msgid "Using :class:`object`"
1166
- msgstr ""
1493
+ msgstr "使用 :class:`object` "
1167
1494
1168
1495
#: ../../howto/enum.rst:1281
1169
1496
msgid "Using :class:`object` would look like::"
1170
- msgstr ""
1497
+ msgstr "使用 :class:`object` 看起來會像這樣: :: "
1171
1498
1172
1499
#: ../../howto/enum.rst:1291
1173
1500
msgid ""
1174
1501
"This is also a good example of why you might want to write your own :meth:"
1175
1502
"`__repr__`::"
1176
- msgstr ""
1503
+ msgstr "這也是為何你有可能會想要撰寫你自己的 :meth:`__repr__` 的好範例: :: "
1177
1504
1178
1505
#: ../../howto/enum.rst:1307
1179
1506
msgid "Using a descriptive string"
1180
- msgstr ""
1507
+ msgstr "使用一個描述性字串 "
1181
1508
1182
1509
#: ../../howto/enum.rst:1309
1183
1510
msgid "Using a string as the value would look like::"
1184
- msgstr ""
1511
+ msgstr "將字串作為值會看起來像這樣: :: "
1185
1512
1186
1513
#: ../../howto/enum.rst:1321
1187
1514
msgid "Using a custom :meth:`__new__`"
1188
- msgstr ""
1515
+ msgstr "使用自訂的 :meth:`__new__` "
1189
1516
1190
1517
#: ../../howto/enum.rst:1323
1191
1518
msgid "Using an auto-numbering :meth:`__new__` would look like::"
1192
- msgstr ""
1519
+ msgstr "使用自動編號的 :meth:`__new__` 看起來會像這樣: :: "
1193
1520
1194
1521
#: ../../howto/enum.rst:1340
1522
+ #, fuzzy
1195
1523
msgid ""
1196
1524
"To make a more general purpose ``AutoNumber``, add ``*args`` to the "
1197
1525
"signature::"
1198
1526
msgstr ""
1527
+ "為了讓``AutoNumber``成為更多用途的程式,請在函式签名中新增 ``*args``: ::"
1199
1528
1200
1529
#: ../../howto/enum.rst:1350
1201
1530
msgid ""
1202
1531
"Then when you inherit from ``AutoNumber`` you can write your own "
1203
1532
"``__init__`` to handle any extra arguments::"
1204
1533
msgstr ""
1534
+ "當你從 ``AutoNumber`` 繼承時,可以撰寫自己的 ``__init__`` 來處理任何額外引"
1535
+ "數: ::"
1205
1536
1206
1537
#: ../../howto/enum.rst:1369
1538
+ #, fuzzy
1207
1539
msgid ""
1208
1540
"The :meth:`__new__` method, if defined, is used during creation of the Enum "
1209
1541
"members; it is then replaced by Enum's :meth:`__new__` which is used after "
1210
1542
"class creation for lookup of existing members."
1211
1543
msgstr ""
1544
+ ":meth:`__new__` 方法(如有定義)將在建立列舉成員期間使用;然後它被列舉的 :"
1545
+ "meth:`__new__` 替換,該 :meth:`__new__` 在類別建立後用於尋找現有成員。"
1212
1546
1213
1547
#: ../../howto/enum.rst:1375
1548
+ #, fuzzy
1214
1549
msgid ""
1215
1550
"*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the "
1216
1551
"one that is found; instead, use the data type directly -- e.g.::"
1217
1552
msgstr ""
1553
+ "*不要*\\ 呼叫 ``super().__new__()``,因為只查找 ``__new__`` 是找到的;相反,"
1554
+ "直接使用資料型別—例如::"
1218
1555
1219
1556
#: ../../howto/enum.rst:1382
1220
1557
msgid "OrderedEnum"
1221
- msgstr ""
1558
+ msgstr "OrderedEnum "
1222
1559
1223
1560
#: ../../howto/enum.rst:1384
1561
+ #, fuzzy
1224
1562
msgid ""
1225
1563
"An ordered enumeration that is not based on :class:`IntEnum` and so "
1226
1564
"maintains the normal :class:`Enum` invariants (such as not being comparable "
1227
1565
"to other enumerations)::"
1228
1566
msgstr ""
1567
+ "一個有序的列舉,它不依據 :class:`IntEnum` 類別而是遵循正常的 :class:`Enum` 不"
1568
+ "變量 (例如不能與其他列舉進行比較): ::"
1229
1569
1230
1570
#: ../../howto/enum.rst:1418
1231
1571
msgid "DuplicateFreeEnum"
1232
- msgstr ""
1572
+ msgstr "DuplicateFreeEnum "
1233
1573
1234
1574
#: ../../howto/enum.rst:1420
1575
+ #, fuzzy
1235
1576
msgid ""
1236
1577
"Raises an error if a duplicate member value is found instead of creating an "
1237
1578
"alias::"
1238
- msgstr ""
1579
+ msgstr "如果出現重複的成員值而不是建立別名,則會引發錯誤: :: "
1239
1580
1240
1581
#: ../../howto/enum.rst:1445
1582
+ #, fuzzy
1241
1583
msgid ""
1242
1584
"This is a useful example for subclassing Enum to add or change other "
1243
1585
"behaviors as well as disallowing aliases. If the only desired change is "
1244
1586
"disallowing aliases, the :func:`unique` decorator can be used instead."
1245
1587
msgstr ""
1588
+ "這是一個有用的範例,可以透過繼承 Enum 來添加或修改其他行為以及禁止別名。如果"
1589
+ "唯一需要的更改是禁止使用別名,那麼可以使用 :func:`unique` 裝飾器。"
1246
1590
1247
1591
#: ../../howto/enum.rst:1451
1248
1592
msgid "Planet"
1249
- msgstr ""
1593
+ msgstr "Planet "
1250
1594
1251
1595
#: ../../howto/enum.rst:1453
1596
+ #, fuzzy
1252
1597
msgid ""
1253
1598
"If :meth:`__new__` or :meth:`__init__` is defined, the value of the enum "
1254
1599
"member will be passed to those methods::"
1255
1600
msgstr ""
1601
+ "如果定義了 :meth:`__new__` 或是 :meth:`__init__`,將會把該列舉成員的值傳遞給"
1602
+ "這些方法: ::"
1256
1603
1257
1604
#: ../../howto/enum.rst:1482
1258
1605
msgid "TimePeriod"
1259
- msgstr ""
1606
+ msgstr "TimePeriod "
1260
1607
1261
1608
#: ../../howto/enum.rst:1484
1262
1609
msgid "An example to show the :attr:`_ignore_` attribute in use::"
1263
- msgstr ""
1610
+ msgstr "一個展示使用 :attr:`_ignore_` 屬性的範例: :: "
1264
1611
1265
1612
#: ../../howto/enum.rst:1503
1266
1613
msgid "Subclassing EnumType"
1267
- msgstr ""
1614
+ msgstr "子類別化 EnumType "
1268
1615
1269
1616
#: ../../howto/enum.rst:1505
1617
+ #, fuzzy
1270
1618
msgid ""
1271
1619
"While most enum needs can be met by customizing :class:`Enum` subclasses, "
1272
1620
"either with class decorators or custom functions, :class:`EnumType` can be "
1273
1621
"subclassed to provide a different Enum experience."
1274
1622
msgstr ""
1623
+ "雖然大部分的列舉需求可以透過客製化 :class:`Enum` subclasses,藉由使用類別裝飾"
1624
+ "器或是自定義的函式來應付,在創造另一種不同的列舉體驗時,可以建立 :class:"
1625
+ "`EnumType` 子類別。"
0 commit comments