Skip to content

Commit 747a9e4

Browse files
Copilotmattwang44
andcommitted
Complete major sections of descriptor primer translation
Co-authored-by: mattwang44 <[email protected]>
1 parent b3a4eb3 commit 747a9e4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

howto/descriptor.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ msgid ""
294294
"An interactive session shows that all access to the managed attribute *age* "
295295
"is logged, but that the regular attribute *name* is not logged:"
296296
msgstr ""
297+
"互動式工作階段顯示對受管理屬性 *age* 的所有存取都被記錄,但一般屬性 *name* 則不會被記錄:"
297298

298299
#: ../../howto/descriptor.rst:181
299300
msgid ""
@@ -332,6 +333,7 @@ msgid ""
332333
"only have one logged attribute and that its name is unchangeable. In the "
333334
"next example, we'll fix that problem."
334335
msgstr ""
336+
"這個範例的一個主要問題是私有名稱 *_age* 在 *LoggedAgeAccess* 類別中是硬編碼的。這意味著每個實例只能有一個被記錄的屬性,而且它的名稱是不可變的。在下一個範例中,我們將修正這個問題。"
335337

336338
#: ../../howto/descriptor.rst:213
337339
msgid "Customized names"
@@ -352,6 +354,7 @@ msgid ""
352354
"names can be recorded, giving each descriptor its own *public_name* and "
353355
"*private_name*:"
354356
msgstr ""
357+
"在這個範例中,:class:`!Person` 類別有兩個描述器實例:*name* 和 *age*。當定義 :class:`!Person` 類別時,它會對 *LoggedAccess* 中的 :meth:`~object.__set_name__` 進行回呼,以便記錄欄位名稱,讓每個描述器都有自己的 *public_name* 和 *private_name*:"
355358

356359
#: ../../howto/descriptor.rst:223
357360
msgid ""
@@ -462,32 +465,37 @@ msgid ""
462465
"where it was created or the name of class variable it was assigned to. "
463466
"(This method, if present, is called even if the class is not a descriptor.)"
464467
msgstr ""
468+
"描述器可以選擇性地擁有 :meth:`~object.__set_name__` 方法。這只在描述器需要知道建立它的類別或被指派的類別變數名稱時使用。(此方法如果存在,即使類別不是描述器也會被呼叫。)"
465469

466470
#: ../../howto/descriptor.rst:305
467471
msgid ""
468472
"Descriptors get invoked by the dot operator during attribute lookup. If a "
469473
"descriptor is accessed indirectly with ``vars(some_class)"
470474
"[descriptor_name]``, the descriptor instance is returned without invoking it."
471475
msgstr ""
476+
"描述器在屬性查找期間由點運算子呼叫。如果描述器是透過 ``vars(some_class)[descriptor_name]`` 間接存取,會回傳描述器實例而不呼叫它。"
472477

473478
#: ../../howto/descriptor.rst:309
474479
msgid ""
475480
"Descriptors only work when used as class variables. When put in instances, "
476481
"they have no effect."
477482
msgstr ""
483+
"描述器只有在用作類別變數時才能運作。當放在實例中時,它們沒有效果。"
478484

479485
#: ../../howto/descriptor.rst:312
480486
msgid ""
481487
"The main motivation for descriptors is to provide a hook allowing objects "
482488
"stored in class variables to control what happens during attribute lookup."
483489
msgstr ""
490+
"描述器的主要動機是提供一個掛鉤,讓儲存在類別變數中的物件能夠控制屬性查找期間發生的事情。"
484491

485492
#: ../../howto/descriptor.rst:315
486493
msgid ""
487494
"Traditionally, the calling class controls what happens during lookup. "
488495
"Descriptors invert that relationship and allow the data being looked-up to "
489496
"have a say in the matter."
490497
msgstr ""
498+
"傳統上,呼叫的類別控制查找期間發生的事情。描述器顛倒了這種關係,讓被查找的資料在這件事上有發言權。"
491499

492500
#: ../../howto/descriptor.rst:319
493501
msgid ""
@@ -496,6 +504,7 @@ msgid ""
496504
"like :func:`classmethod`, :func:`staticmethod`, :func:`property`, "
497505
"and :func:`functools.cached_property` are all implemented as descriptors."
498506
msgstr ""
507+
"描述器在整個語言中被廣泛使用。函式就是透過這種方式轉變為綁定方法。常見工具如 :func:`classmethod`、:func:`staticmethod`、:func:`property` 和 :func:`functools.cached_property` 都是以描述器實作的。"
499508

500509
#: ../../howto/descriptor.rst:326
501510
msgid "Complete Practical Example"

0 commit comments

Comments
 (0)