Skip to content

Commit 53e3dee

Browse files
committed
feat: Add code preservation and __import__ pattern
- Add is_complete_python_code() to preserve original code blocks - Replace translated code with original when msgid is valid Python - Add pattern to handle __import__ statements with virgules
1 parent acfba0e commit 53e3dee

13 files changed

Lines changed: 487 additions & 461 deletions

library/functions.po

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ msgid ""
528528
" return False\n"
529529
" return True"
530530
msgstr ""
531-
"تعریف همه (تکرارپذیر):\n"
532-
" برای عنصر در iterable:\n"
533-
" اگر نه عنصر:\n"
534-
" بازگشت نادرست\n"
535-
" بازگشت درست است"
531+
"def all(iterable):\n"
532+
" for element in iterable:\n"
533+
" if not element:\n"
534+
" return False\n"
535+
" return True"
536536

537537
#: library/functions.rst:89
538538
#, fuzzy
@@ -581,11 +581,11 @@ msgid ""
581581
" return True\n"
582582
" return False"
583583
msgstr ""
584-
"تعریف هر (تکرارپذیر):\n"
585-
" برای عنصر در iterable:\n"
586-
" عنصر if:\n"
587-
" بازگشت درست است\n"
588-
" بازگشت نادرست"
584+
"def any(iterable):\n"
585+
" for element in iterable:\n"
586+
" if element:\n"
587+
" return True\n"
588+
" return False"
589589

590590
#: library/functions.rst:116
591591
#, fuzzy
@@ -875,7 +875,7 @@ msgid ""
875875
" @classmethod\n"
876876
" def f(cls, arg1, arg2): ..."
877877
msgstr ""
878-
"کلاس C:\n"
878+
"class C:\n"
879879
" @classmethod\n"
880880
" def f(cls, arg1, arg2): ..."
881881

@@ -1439,10 +1439,10 @@ msgid ""
14391439
" yield n, elem\n"
14401440
" n += 1"
14411441
msgstr ""
1442-
"def enumerate (تکرارپذیر, start=0):\n"
1443-
" n = شروع\n"
1444-
" برای عنصر در تکرارپذیر:\n"
1445-
" بازده n، elem\n"
1442+
"def enumerate(iterable, start=0):\n"
1443+
" n = start\n"
1444+
" for elem in iterable:\n"
1445+
" yield n, elem\n"
14461446
" n += 1"
14471447

14481448
#: library/functions.rst:0
@@ -2403,10 +2403,10 @@ msgid ""
24032403
" for block in iter(partial(f.read, 64), b''):\n"
24042404
" process_block(block)"
24052405
msgstr ""
2406-
"از functools واردات جزئی\n"
2407-
"با open('mydata.db', 'rb') به صورت f:\n"
2408-
" برای بلوک در iter(partial(f.read, 64), b''):\n"
2409-
" process_block (block)"
2406+
"from functools import partial\n"
2407+
"with open('mydata.db', 'rb') as f:\n"
2408+
" for block in iter(partial(f.read, 64), b''):\n"
2409+
" process_block(block)"
24102410

24112411
#: library/functions.rst:1129
24122412
#, fuzzy
@@ -3480,20 +3480,20 @@ msgid ""
34803480
"\n"
34813481
" x = property(getx, setx, delx, \"I'm the 'x' property.\")"
34823482
msgstr ""
3483-
"کلاس C:\n"
3483+
"class C:\n"
34843484
" def __init__(self):\n"
3485-
" self._x = هیچکدام\n"
3485+
" self._x = None\n"
34863486
"\n"
34873487
" def getx(self):\n"
3488-
" خود را برگردان._x\n"
3488+
" return self._x\n"
34893489
"\n"
3490-
" def setx(خود, ارزش):\n"
3491-
" خود._x = ارزش\n"
3490+
" def setx(self, value):\n"
3491+
" self._x = value\n"
34923492
"\n"
3493-
" def delx (خود):\n"
3494-
" دل خود._x\n"
3493+
" def delx(self):\n"
3494+
" del self._x\n"
34953495
"\n"
3496-
" x = ویژگی (getx, setx, delx, \"من ویژگی \"x\" هستم.\")"
3496+
" x = property(getx, setx, delx, \"I'm the 'x' property.\")"
34973497

34983498
#: library/functions.rst:1653
34993499
#, fuzzy
@@ -3529,14 +3529,14 @@ msgid ""
35293529
" \"\"\"Get the current voltage.\"\"\"\n"
35303530
" return self._voltage"
35313531
msgstr ""
3532-
"طوطی کلاس:\n"
3532+
"class Parrot:\n"
35333533
" def __init__(self):\n"
3534-
" خود._ولتاژ = 100000\n"
3534+
" self._voltage = 100000\n"
35353535
"\n"
35363536
" @property\n"
3537-
" ولتاژ دف (خود):\n"
3538-
" \"\"\"ولتاژ فعلی را دریافت کنید.\"\"\"\n"
3539-
" بازگشت خود._ولتاژ"
3537+
" def voltage(self):\n"
3538+
" \"\"\"Get the current voltage.\"\"\"\n"
3539+
" return self._voltage"
35403540

35413541
#: library/functions.rst:1669
35423542
#, fuzzy
@@ -3582,22 +3582,22 @@ msgid ""
35823582
" def x(self):\n"
35833583
" del self._x"
35843584
msgstr ""
3585-
"کلاس C:\n"
3585+
"class C:\n"
35863586
" def __init__(self):\n"
3587-
" self._x = هیچکدام\n"
3587+
" self._x = None\n"
35883588
"\n"
35893589
" @property\n"
35903590
" def x(self):\n"
3591-
" \"\"\"من ویژگی \"x\" هستم.\"\"\"\n"
3592-
" خود را برگردان._x\n"
3591+
" \"\"\"I'm the 'x' property.\"\"\"\n"
3592+
" return self._x\n"
35933593
"\n"
35943594
" @x.setter\n"
3595-
" def x(خود, ارزش):\n"
3596-
" خود._x = ارزش\n"
3595+
" def x(self, value):\n"
3596+
" self._x = value\n"
35973597
"\n"
35983598
" @x.deleter\n"
35993599
" def x(self):\n"
3600-
" دل خود._x"
3600+
" del self._x"
36013601

36023602
#: library/functions.rst:1701
36033603
#, fuzzy
@@ -3677,13 +3677,13 @@ msgid ""
36773677
" def __repr__(self):\n"
36783678
" return f\"Person('{self.name}', {self.age})\""
36793679
msgstr ""
3680-
"فرد کلاس:\n"
3681-
" def __init__(خود, نام, سن):\n"
3682-
" self.name = نام\n"
3683-
" خود. سن = سن\n"
3680+
"class Person:\n"
3681+
" def __init__(self, name, age):\n"
3682+
" self.name = name\n"
3683+
" self.age = age\n"
36843684
"\n"
3685-
" def __repr__(خود):\n"
3686-
" بازگشت f\"Person('{self.name}', {self.age})\""
3685+
" def __repr__(self):\n"
3686+
" return f\"Person('{self.name}', {self.age})\""
36873687

36883688
#: library/functions.rst:1754
36893689
#, fuzzy
@@ -3964,7 +3964,7 @@ msgid ""
39643964
" @staticmethod\n"
39653965
" def f(arg1, arg2, argN): ..."
39663966
msgstr ""
3967-
"کلاس C:\n"
3967+
"class C:\n"
39683968
" @staticmethod\n"
39693969
" def f(arg1, arg2, argN): ..."
39703970

@@ -4027,8 +4027,8 @@ msgstr ""
40274027
"def regular_function():\n"
40284028
" ...\n"
40294029
"\n"
4030-
"کلاس C:\n"
4031-
" روش = روش استاتیک (تابع_معمول)"
4030+
"class C:\n"
4031+
" method = staticmethod(regular_function)"
40324032

40334033
#: library/functions.rst:1915
40344034
#, fuzzy
@@ -4230,10 +4230,10 @@ msgid ""
42304230
" super().method(arg) # This does the same thing as:\n"
42314231
" # super(C, self).method(arg)"
42324232
msgstr ""
4233-
"کلاس C(B):\n"
4234-
" روش def (خود, arg):\n"
4235-
" super().method(arg) # این همان کار را انجام می دهد:\n"
4236-
" # روش super(C, self).(arg)"
4233+
"class C(B):\n"
4234+
" def method(self, arg):\n"
4235+
" super().method(arg) # This does the same thing as:\n"
4236+
" # super(C, self).method(arg)"
42374237

42384238
#: library/functions.rst:2012
42394239
#, fuzzy
@@ -4727,7 +4727,7 @@ msgstr ""
47274727
#: library/functions.rst:2248
47284728
#, fuzzy
47294729
msgid "spam = __import__('spam', globals(), locals(), [], 0)"
4730-
msgstr "هرزنامه = __import__('spam', globals(), locals()، [], 0)"
4730+
msgstr "spam = __import__('spam', globals(), locals(), [], 0)"
47314731

47324732
#: library/functions.rst:2250
47334733
#, fuzzy
@@ -4737,7 +4737,7 @@ msgstr "عبارت ``import spam.ham`` در این فراخوانی نتیجه
47374737
#: library/functions.rst:2252
47384738
#, fuzzy
47394739
msgid "spam = __import__('spam.ham', globals(), locals(), [], 0)"
4740-
msgstr "هرزنامه = __import__('spam.ham', globals(), locals()، [], 0)"
4740+
msgstr "spam = __import__('spam.ham', globals(), locals(), [], 0)"
47414741

47424742
#: library/functions.rst:2254
47434743
#, fuzzy
@@ -4765,9 +4765,9 @@ msgid ""
47654765
"eggs = _temp.eggs\n"
47664766
"saus = _temp.sausage"
47674767
msgstr ""
4768-
"_temp = __import__('spam.ham', globals(), locals()، ['تخم مرغ', 'سوسیس'], 0)\n"
4769-
"تخم مرغ = _temp.eggs\n"
4770-
"saus = _temp.سوسیس"
4768+
"_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], 0)\n"
4769+
"eggs = _temp.eggs\n"
4770+
"saus = _temp.sausage"
47714771

47724772
#: library/functions.rst:2264
47734773
#, fuzzy
@@ -4856,7 +4856,7 @@ msgstr "بی نهایت"
48564856
#: library/functions.rst:814
48574857
#, fuzzy
48584858
msgid "__format__"
4859-
msgstr "__قالب__"
4859+
msgstr "__format__"
48604860

48614861
#: library/functions.rst:814 library/functions.rst:1925
48624862
#, fuzzy

0 commit comments

Comments
 (0)