Skip to content

Commit 3449ca8

Browse files
Copilotmattwang44
andcommitted
Complete translation of all tutorial .po files - 57 entries translated and 2 fuzzy entries fixed
Co-authored-by: mattwang44 <24987826+mattwang44@users.noreply.github.com>
1 parent fc9f3ef commit 3449ca8

File tree

6 files changed

+260
-1
lines changed

6 files changed

+260
-1
lines changed

tutorial/classes.po

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,28 @@ msgid ""
375375
"scope_test()\n"
376376
"print(\"In global scope:\", spam)"
377377
msgstr ""
378+
"def scope_test():\n"
379+
" def do_local():\n"
380+
" spam = \"local spam\"\n"
381+
"\n"
382+
" def do_nonlocal():\n"
383+
" nonlocal spam\n"
384+
" spam = \"nonlocal spam\"\n"
385+
"\n"
386+
" def do_global():\n"
387+
" global spam\n"
388+
" spam = \"global spam\"\n"
389+
"\n"
390+
" spam = \"test spam\"\n"
391+
" do_local()\n"
392+
" print(\"After local assignment:\", spam)\n"
393+
" do_nonlocal()\n"
394+
" print(\"After nonlocal assignment:\", spam)\n"
395+
" do_global()\n"
396+
" print(\"After global assignment:\", spam)\n"
397+
"\n"
398+
"scope_test()\n"
399+
"print(\"In global scope:\", spam)"
378400

379401
#: ../../tutorial/classes.rst:191
380402
msgid "The output of the example code is:"
@@ -387,6 +409,10 @@ msgid ""
387409
"After global assignment: nonlocal spam\n"
388410
"In global scope: global spam"
389411
msgstr ""
412+
"After local assignment: test spam\n"
413+
"After nonlocal assignment: nonlocal spam\n"
414+
"After global assignment: nonlocal spam\n"
415+
"In global scope: global spam"
390416

391417
#: ../../tutorial/classes.rst:200
392418
msgid ""
@@ -665,6 +691,7 @@ msgid ""
665691
"The other kind of instance attribute reference is a *method*. A method is a "
666692
"function that \"belongs to\" an object."
667693
msgstr ""
694+
"另一種執行個體屬性參考是 *方法* (method)。方法是\"屬於\"一個物件的函式。"
668695

669696
#: ../../tutorial/classes.rst:345
670697
msgid ""
@@ -795,6 +822,23 @@ msgid ""
795822
">>> e.name # unique to e\n"
796823
"'Buddy'"
797824
msgstr ""
825+
"class Dog:\n"
826+
"\n"
827+
" kind = 'canine' # class variable shared by all instances\n"
828+
"\n"
829+
" def __init__(self, name):\n"
830+
" self.name = name # instance variable unique to each instance\n"
831+
"\n"
832+
">>> d = Dog('Fido')\n"
833+
">>> e = Dog('Buddy')\n"
834+
">>> d.kind # shared by all dogs\n"
835+
"'canine'\n"
836+
">>> e.kind # shared by all dogs\n"
837+
"'canine'\n"
838+
">>> d.name # unique to d\n"
839+
"'Fido'\n"
840+
">>> e.name # unique to e\n"
841+
"'Buddy'"
798842

799843
#: ../../tutorial/classes.rst:422
800844
msgid ""
@@ -1363,6 +1407,24 @@ msgid ""
13631407
" for item in zip(keys, values):\n"
13641408
" self.items_list.append(item)"
13651409
msgstr ""
1410+
"class Mapping:\n"
1411+
" def __init__(self, iterable):\n"
1412+
" self.items_list = []\n"
1413+
" self.__update(iterable)\n"
1414+
"\n"
1415+
" def update(self, iterable):\n"
1416+
" for item in iterable:\n"
1417+
" self.items_list.append(item)\n"
1418+
"\n"
1419+
" __update = update # private copy of original update() method\n"
1420+
"\n"
1421+
"class MappingSubclass(Mapping):\n"
1422+
"\n"
1423+
" def update(self, keys, values):\n"
1424+
" # provides new signature for update()\n"
1425+
" # but does not break __init__()\n"
1426+
" for item in zip(keys, values):\n"
1427+
" self.items_list.append(item)"
13661428

13671429
#: ../../tutorial/classes.rst:718
13681430
msgid ""
@@ -1592,6 +1654,20 @@ msgid ""
15921654
" self.index = self.index - 1\n"
15931655
" return self.data[self.index]"
15941656
msgstr ""
1657+
"class Reverse:\n"
1658+
" \"\"\"Iterator for looping over a sequence backwards.\"\"\"\n"
1659+
" def __init__(self, data):\n"
1660+
" self.data = data\n"
1661+
" self.index = len(data)\n"
1662+
"\n"
1663+
" def __iter__(self):\n"
1664+
" return self\n"
1665+
"\n"
1666+
" def __next__(self):\n"
1667+
" if self.index == 0:\n"
1668+
" raise StopIteration\n"
1669+
" self.index = self.index - 1\n"
1670+
" return self.data[self.index]"
15951671

15961672
#: ../../tutorial/classes.rst:845
15971673
msgid ""
@@ -1737,6 +1813,22 @@ msgid ""
17371813
">>> list(data[i] for i in range(len(data)-1, -1, -1))\n"
17381814
"['f', 'l', 'o', 'g']"
17391815
msgstr ""
1816+
">>> sum(i*i for i in range(10)) # sum of squares\n"
1817+
"285\n"
1818+
"\n"
1819+
">>> xvec = [10, 20, 30]\n"
1820+
">>> yvec = [7, 5, 3]\n"
1821+
">>> sum(x*y for x,y in zip(xvec, yvec)) # dot product\n"
1822+
"260\n"
1823+
"\n"
1824+
">>> unique_words = set(word for line in page for word in line.split())\n"
1825+
"\n"
1826+
">>> valedictorian = max((student.gpa, student.name) for student in "
1827+
"graduates)\n"
1828+
"\n"
1829+
">>> data = 'golf'\n"
1830+
">>> list(data[i] for i in range(len(data)-1, -1, -1))\n"
1831+
"['f', 'l', 'o', 'g']"
17401832

17411833
#: ../../tutorial/classes.rst:932
17421834
msgid "Footnotes"

tutorial/datastructures.po

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,33 @@ msgid ""
457457
">>> [num for elem in vec for num in elem]\n"
458458
"[1, 2, 3, 4, 5, 6, 7, 8, 9]"
459459
msgstr ""
460+
">>> vec = [-4, -2, 0, 2, 4]\n"
461+
">>> # create a new list with the values doubled\n"
462+
">>> [x*2 for x in vec]\n"
463+
"[-8, -4, 0, 4, 8]\n"
464+
">>> # filter the list to exclude negative numbers\n"
465+
">>> [x for x in vec if x >= 0]\n"
466+
"[0, 2, 4]\n"
467+
">>> # apply a function to all the elements\n"
468+
">>> [abs(x) for x in vec]\n"
469+
"[4, 2, 0, 2, 4]\n"
470+
">>> # call a method on each element\n"
471+
">>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']\n"
472+
">>> [weapon.strip() for weapon in freshfruit]\n"
473+
"['banana', 'loganberry', 'passion fruit']\n"
474+
">>> # create a list of 2-tuples like (number, square)\n"
475+
">>> [(x, x**2) for x in range(6)]\n"
476+
"[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]\n"
477+
">>> # the tuple must be parenthesized, otherwise an error is raised\n"
478+
">>> [x, x**2 for x in range(6)]\n"
479+
" File \"<stdin>\", line 1\n"
480+
" [x, x**2 for x in range(6)]\n"
481+
" ^^^^^^^\n"
482+
"SyntaxError: did you forget parentheses around the comprehension target?\n"
483+
">>> # flatten a list using a listcomp with two 'for'\n"
484+
">>> vec = [[1,2,3], [4,5,6], [7,8,9]]\n"
485+
">>> [num for elem in vec for num in elem]\n"
486+
"[1, 2, 3, 4, 5, 6, 7, 8, 9]"
460487

461488
#: ../../tutorial/datastructures.rst:279
462489
msgid ""
@@ -856,6 +883,29 @@ msgid ""
856883
">>> a ^ b # letters in a or b but not both\n"
857884
"{'r', 'd', 'b', 'm', 'z', 'l'}"
858885
msgstr ""
886+
">>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n"
887+
">>> print(basket) # show that duplicates have been "
888+
"removed\n"
889+
"{'orange', 'banana', 'pear', 'apple'}\n"
890+
">>> 'orange' in basket # fast membership testing\n"
891+
"True\n"
892+
">>> 'crabgrass' in basket\n"
893+
"False\n"
894+
"\n"
895+
">>> # Demonstrate set operations on unique letters from two words\n"
896+
">>>\n"
897+
">>> a = set('abracadabra')\n"
898+
">>> b = set('alacazam')\n"
899+
">>> a # unique letters in a\n"
900+
"{'a', 'r', 'b', 'c', 'd'}\n"
901+
">>> a - b # letters in a but not in b\n"
902+
"{'r', 'd', 'b'}\n"
903+
">>> a | b # letters in a or b or both\n"
904+
"{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}\n"
905+
">>> a & b # letters in both a and b\n"
906+
"{'a', 'c'}\n"
907+
">>> a ^ b # letters in a or b but not both\n"
908+
"{'r', 'd', 'b', 'm', 'z', 'l'}"
859909

860910
#: ../../tutorial/datastructures.rst:482
861911
msgid ""

tutorial/floatingpoint.po

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ msgid ""
215215
">>> repr(math.pi)\n"
216216
"'3.141592653589793'"
217217
msgstr ""
218+
">>> format(math.pi, '.12g') # give 12 significant digits\n"
219+
"'3.14159265359'\n"
220+
"\n"
221+
">>> format(math.pi, '.2f') # give 2 digits after the point\n"
222+
"'3.14'\n"
223+
"\n"
224+
">>> repr(math.pi)\n"
225+
"'3.141592653589793'"
218226

219227
#: ../../tutorial/floatingpoint.rst:111
220228
msgid ""
@@ -492,6 +500,23 @@ msgid ""
492500
"digits!\n"
493501
"-0.0051575902860057365"
494502
msgstr ""
503+
">>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,\n"
504+
"... -143401161400469.7, 266262841.31058735, -0.003244936839808227]\n"
505+
">>> float(sum(map(Fraction, arr))) # Exact summation with single rounding\n"
506+
"8.042173697819788e-13\n"
507+
">>> math.fsum(arr) # Single rounding\n"
508+
"8.042173697819788e-13\n"
509+
">>> sum(arr) # Multiple roundings in extended "
510+
"precision\n"
511+
"8.042178034628478e-13\n"
512+
">>> total = 0.0\n"
513+
">>> for x in arr:\n"
514+
"... total += x # Multiple roundings in standard "
515+
"precision\n"
516+
"...\n"
517+
">>> total # Straight addition has no correct "
518+
"digits!\n"
519+
"-0.0051575902860057365"
495520

496521
#: ../../tutorial/floatingpoint.rst:260
497522
msgid "Representation Error"

tutorial/interpreter.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ msgid ""
221221
"...\n"
222222
"Be careful not to fall off!"
223223
msgstr ""
224+
">>> the_world_is_flat = True\n"
225+
">>> if the_world_is_flat:\n"
226+
"... print(\"Be careful not to fall off!\")\n"
227+
"...\n"
228+
"Be careful not to fall off!"
224229

225230
#: ../../tutorial/interpreter.rst:118
226231
msgid "For more on interactive mode, see :ref:`tut-interac`."
@@ -274,7 +279,7 @@ msgstr "比如,聲明使用 Windows-1252 編碼,源碼檔案要寫成: ::"
274279

275280
#: ../../tutorial/interpreter.rst:150
276281
msgid "# -*- coding: cp1252 -*-"
277-
msgstr ""
282+
msgstr "# -*- coding: cp1252 -*-"
278283

279284
#: ../../tutorial/interpreter.rst:152
280285
msgid ""

tutorial/modules.po

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,29 @@ msgid ""
861861
" karaoke.py\n"
862862
" ..."
863863
msgstr ""
864+
"sound/ Top-level package\n"
865+
" __init__.py Initialize the sound package\n"
866+
" formats/ Subpackage for file format conversions\n"
867+
" __init__.py\n"
868+
" wavread.py\n"
869+
" wavwrite.py\n"
870+
" aiffread.py\n"
871+
" aiffwrite.py\n"
872+
" auread.py\n"
873+
" auwrite.py\n"
874+
" ...\n"
875+
" effects/ Subpackage for sound effects\n"
876+
" __init__.py\n"
877+
" echo.py\n"
878+
" surround.py\n"
879+
" reverse.py\n"
880+
" ...\n"
881+
" filters/ Subpackage for filters\n"
882+
" __init__.py\n"
883+
" equalizer.py\n"
884+
" vocoder.py\n"
885+
" karaoke.py\n"
886+
" ..."
864887

865888
#: ../../tutorial/modules.rst:438
866889
msgid ""
@@ -1046,6 +1069,14 @@ msgid ""
10461069
"def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule\n"
10471070
" return msg[::-1] # in the case of a 'from sound.effects import *'"
10481071
msgstr ""
1072+
"__all__ = [\n"
1073+
" \"echo\", # refers to the 'echo.py' file\n"
1074+
" \"surround\", # refers to the 'surround.py' file\n"
1075+
" \"reverse\", # !!! refers to the 'reverse' function now !!!\n"
1076+
"]\n"
1077+
"\n"
1078+
"def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule\n"
1079+
" return msg[::-1] # in the case of a 'from sound.effects import *'"
10491080

10501081
#: ../../tutorial/modules.rst:534
10511082
msgid ""

tutorial/stdlib2.po

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ msgid ""
145145
"... conv['frac_digits'], x), grouping=True)\n"
146146
"'$1,234,567.80'"
147147
msgstr ""
148+
">>> import locale\n"
149+
">>> locale.setlocale(locale.LC_ALL, 'English_United States.1252')\n"
150+
"'English_United States.1252'\n"
151+
">>> conv = locale.localeconv() # get a mapping of conventions\n"
152+
">>> x = 1234567.8\n"
153+
">>> locale.format_string(\"%d\", x, grouping=True)\n"
154+
"'1,234,567'\n"
155+
">>> locale.format_string(\"%s%.*f\", (conv['currency_symbol'],\n"
156+
"... conv['frac_digits'], x), grouping=True)\n"
157+
"'$1,234,567.80'"
148158

149159
#: ../../tutorial/stdlib2.rst:72
150160
msgid "Templating"
@@ -321,6 +331,24 @@ msgid ""
321331
"\n"
322332
" start += extra_size + comp_size # skip to the next header"
323333
msgstr ""
334+
"import struct\n"
335+
"\n"
336+
"with open('myfile.zip', 'rb') as f:\n"
337+
" data = f.read()\n"
338+
"\n"
339+
"start = 0\n"
340+
"for i in range(3): # show the first 3 file headers\n"
341+
" start += 14\n"
342+
" fields = struct.unpack('<IIIHH', data[start:start+16])\n"
343+
" crc32, comp_size, uncomp_size, filenamesize, extra_size = fields\n"
344+
"\n"
345+
" start += 16\n"
346+
" filename = data[start:start+filenamesize]\n"
347+
" start += filenamesize\n"
348+
" extra = data[start:start+extra_size]\n"
349+
" print(filename, hex(crc32), comp_size, uncomp_size)\n"
350+
"\n"
351+
" start += extra_size + comp_size # skip to the next header"
324352

325353
#: ../../tutorial/stdlib2.rst:167
326354
msgid "Multi-threading"
@@ -543,6 +571,28 @@ msgid ""
543571
" o = self.data[key]()\n"
544572
"KeyError: 'primary'"
545573
msgstr ""
574+
">>> import weakref, gc\n"
575+
">>> class A:\n"
576+
"... def __init__(self, value):\n"
577+
"... self.value = value\n"
578+
"... def __repr__(self):\n"
579+
"... return str(self.value)\n"
580+
"...\n"
581+
">>> a = A(10) # create a reference\n"
582+
">>> d = weakref.WeakValueDictionary()\n"
583+
">>> d['primary'] = a # does not create a reference\n"
584+
">>> d['primary'] # fetch the object if it is still alive\n"
585+
"10\n"
586+
">>> del a # remove the one reference\n"
587+
">>> gc.collect() # run garbage collection right away\n"
588+
"0\n"
589+
">>> d['primary'] # entry was automatically removed\n"
590+
"Traceback (most recent call last):\n"
591+
" File \"<stdin>\", line 1, in <module>\n"
592+
" d['primary'] # entry was automatically removed\n"
593+
" File \"C:/python313/lib/weakref.py\", line 46, in __getitem__\n"
594+
" o = self.data[key]()\n"
595+
"KeyError: 'primary'"
546596

547597
#: ../../tutorial/stdlib2.rst:290
548598
msgid "Tools for Working with Lists"
@@ -673,6 +723,12 @@ msgid ""
673723
">>> [heappop(data) for i in range(3)] # fetch the three smallest entries\n"
674724
"[-5, 0, 1]"
675725
msgstr ""
726+
">>> from heapq import heapify, heappop, heappush\n"
727+
">>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]\n"
728+
">>> heapify(data) # rearrange the list into heap order\n"
729+
">>> heappush(data, -5) # add a new entry\n"
730+
">>> [heappop(data) for i in range(3)] # fetch the three smallest entries\n"
731+
"[-5, 0, 1]"
676732

677733
#: ../../tutorial/stdlib2.rst:356
678734
msgid "Decimal Floating-Point Arithmetic"

0 commit comments

Comments
 (0)