Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9eaa260

Browse files
author
Reinny Almonte
authored
Merge branch '3.8' into traduccion-imp
2 parents80b72c9 +7a46a63 commit9eaa260

File tree

535 files changed

+93892
-38253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

535 files changed

+93892
-38253
lines changed

‎.gitignore

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
11
*.mo
2+
/_build/
3+
4+
# Submodules to avoid issues
5+
cpython
6+
.migration/tutorialpyar
7+
8+
# Files overriden by our scripts
9+
Doc/tools/templates/customsourcelink.html
10+
Doc/tools/templates/indexsidebar.html
11+
Doc/CONTRIBUTING.rst
12+
Doc/translation-memory.rst
13+
Doc/upgrade-python-version.rst
14+
locales/
15+
dict.txt
16+
17+
# Byte-compiled / optimized / DLL files
18+
__pycache__/
19+
*.py[cod]
20+
21+
# C extensions
22+
*.so
23+
24+
# Distribution / packaging
25+
venv
26+
.venv
27+
.Python
28+
env/
29+
build/
30+
develop-eggs/
31+
dist/
32+
downloads/
33+
eggs/
34+
lib/
35+
lib64/
36+
parts/
37+
sdist/
38+
var/
39+
*.egg-info/
40+
.installed.cfg
41+
*.egg
42+
.mypy_cache/
43+
.python-version
44+
45+
# PyInstaller
46+
# Usually these files are written by a python script from a template
47+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
48+
*.manifest
49+
*.spec
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# Unit test / coverage reports
56+
htmlcov/
57+
.tox/
58+
.coverage
59+
.cache
60+
nosetests.xml
61+
coverage.xml
62+
63+
# Ides
64+
.vscode/
65+
.idea/
66+
/translation-memory.po
67+
/locale/
68+
69+
# OSX
70+
.DS_Store

‎.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[submodule "cpython"]
2+
path=cpython
3+
url=https://github.com/python/cpython.git
4+
branch=3.8
5+
shallow=true
6+
[submodule "tutorialpyar"]
7+
path=.migration/tutorialpyar
8+
url=https://github.com/pyar/tutorial.git

‎.migration/rst2po.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# rst2po.py
2+
# Script to migrate the Python official tutorial that we have already translated in PyAr
3+
# (https://github.com/PyAr/tutorial) from reStructuredText to the new official translation format (.po)
4+
#
5+
# It parses the .rst and compare sentence/paragraph by sentence/paragraph and if the match is exact,
6+
# and there is no translation for that sentence/paragraph it updates the .po file with the translated text
7+
# from the .rst file.
8+
9+
importre
10+
importglob
11+
importos
12+
importpolib# fades
13+
14+
15+
PO_DIR=os.path.abspath(
16+
os.path.join(
17+
os.path.dirname(__file__),
18+
'..',
19+
))
20+
21+
RST_TRADUCIDOS_DIR=os.path.abspath(
22+
os.path.join(
23+
os.path.dirname(__file__),
24+
'tutorialpyar',
25+
'traducidos',
26+
))
27+
28+
RST_ORIGINAL_DIR=os.path.abspath(
29+
os.path.join(
30+
os.path.dirname(__file__),
31+
'tutorialpyar',
32+
'original',
33+
))
34+
35+
36+
37+
defget_rst_file(pofilename):
38+
"""Given a .po filename returns the corresponding .rst filename"""
39+
basename=os.path.basename(pofilename)
40+
basename,ext=basename.rsplit('.',1)
41+
rstfilename=os.path.join(RST_TRADUCIDOS_DIR,f'{basename}.rst')
42+
ifos.path.exists(rstfilename):
43+
returnrstfilename
44+
45+
46+
defget_rst_original_filename(rstfilename):
47+
rst_original_filename=''
48+
ifrstfilename.endswith('real-index.rst'):
49+
rst_original_filename='index.rst'
50+
51+
basename=os.path.basename(rst_original_filenameorrstfilename)
52+
rst_original_filename=os.path.join(RST_ORIGINAL_DIR,basename)
53+
ifos.path.exists(rst_original_filename):
54+
returnrst_original_filename
55+
56+
57+
defcreate_english_spanish_sentences(rstfilename):
58+
"""Create a tuple of (english, spanish) sentences for rstfilename"""
59+
60+
defget_paragraph(fd):
61+
lines= []
62+
paragraph= []
63+
forlineinfd.read().splitlines():
64+
# import pdb; pdb.set_trace()
65+
ifany([
66+
line.startswith('.. '),
67+
line.startswith('==='),
68+
line.startswith('---'),
69+
line.startswith('***'),
70+
]):
71+
continue
72+
73+
ifline==''andnotparagraph:
74+
continue
75+
76+
ifline=='':
77+
lines.append(' '.join(paragraph))
78+
paragraph= []
79+
continue
80+
paragraph.append(line)
81+
82+
returnlines
83+
84+
# NOTE: we could use docutils and parse the rst in the correct way, but
85+
# that will probably take more time
86+
withopen(get_rst_original_filename(rstfilename))asfd:
87+
english=get_paragraph(fd)
88+
89+
withopen(rstfilename)asfd:
90+
spanish=get_paragraph(fd)
91+
92+
result=list(zip(english,spanish))
93+
returnresult
94+
95+
96+
defget_rst_translation_text(rstfilename,english_spanish,text):
97+
"""Given an rstfilename an a text returns the corresponding translated text if exists"""
98+
foren,esinenglish_spanish:
99+
ifen.replace("!","")==text.replace("!",""):
100+
returnes
101+
102+
103+
defupdate_po_translation(pofilename,english,spanish):
104+
"""Update the pofilename with the translated spanish text"""
105+
pass
106+
107+
108+
forpofilenameinglob.glob(PO_DIR+'**/*/*.po'):
109+
translated=False
110+
rstfilename=get_rst_file(pofilename)
111+
ifrstfilenameisNone:
112+
continue
113+
114+
english_spanish=create_english_spanish_sentences(rstfilename)
115+
116+
po=polib.pofile(pofilename)
117+
forentryinpo:
118+
english_text=entry.msgid
119+
spanish_text=entry.msgstr
120+
ifspanish_text:
121+
# Do not override already translated text
122+
continue
123+
124+
translated_text=get_rst_translation_text(rstfilename,english_spanish,english_text)
125+
iftranslated_textisNone:
126+
continue
127+
128+
translated=True
129+
130+
entry.msgstr=translated_text
131+
# update_po_translation(po, english_text, translated_text)
132+
133+
iftranslated:
134+
po.save(pofilename)

‎.migration/tutorialpyar

Submoduletutorialpyar added ate2b1222

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp