Skip to content

Commit 9eaa260

Browse files
author
Reinny Almonte
authored
Merge branch '3.8' into traduccion-imp
2 parents 80b72c9 + 7a46a63 commit 9eaa260

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

+69
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

+8
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

+134
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+
import re
10+
import glob
11+
import os
12+
import polib # 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+
def get_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+
if os.path.exists(rstfilename):
43+
return rstfilename
44+
45+
46+
def get_rst_original_filename(rstfilename):
47+
rst_original_filename = ''
48+
if rstfilename.endswith('real-index.rst'):
49+
rst_original_filename = 'index.rst'
50+
51+
basename = os.path.basename(rst_original_filename or rstfilename)
52+
rst_original_filename = os.path.join(RST_ORIGINAL_DIR, basename)
53+
if os.path.exists(rst_original_filename):
54+
return rst_original_filename
55+
56+
57+
def create_english_spanish_sentences(rstfilename):
58+
"""Create a tuple of (english, spanish) sentences for rstfilename"""
59+
60+
def get_paragraph(fd):
61+
lines = []
62+
paragraph = []
63+
for line in fd.read().splitlines():
64+
# import pdb; pdb.set_trace()
65+
if any([
66+
line.startswith('.. '),
67+
line.startswith('==='),
68+
line.startswith('---'),
69+
line.startswith('***'),
70+
]):
71+
continue
72+
73+
if line == '' and not paragraph:
74+
continue
75+
76+
if line == '':
77+
lines.append(' '.join(paragraph))
78+
paragraph = []
79+
continue
80+
paragraph.append(line)
81+
82+
return lines
83+
84+
# NOTE: we could use docutils and parse the rst in the correct way, but
85+
# that will probably take more time
86+
with open(get_rst_original_filename(rstfilename)) as fd:
87+
english = get_paragraph(fd)
88+
89+
with open(rstfilename) as fd:
90+
spanish = get_paragraph(fd)
91+
92+
result = list(zip(english, spanish))
93+
return result
94+
95+
96+
def get_rst_translation_text(rstfilename, english_spanish, text):
97+
"""Given an rstfilename an a text returns the corresponding translated text if exists"""
98+
for en, es in english_spanish:
99+
if en.replace("!", "") == text.replace("!", ""):
100+
return es
101+
102+
103+
def update_po_translation(pofilename, english, spanish):
104+
"""Update the pofilename with the translated spanish text"""
105+
pass
106+
107+
108+
for pofilename in glob.glob(PO_DIR + '**/*/*.po'):
109+
translated = False
110+
rstfilename = get_rst_file(pofilename)
111+
if rstfilename is None:
112+
continue
113+
114+
english_spanish = create_english_spanish_sentences(rstfilename)
115+
116+
po = polib.pofile(pofilename)
117+
for entry in po:
118+
english_text = entry.msgid
119+
spanish_text = entry.msgstr
120+
if spanish_text:
121+
# Do not override already translated text
122+
continue
123+
124+
translated_text = get_rst_translation_text(rstfilename, english_spanish, english_text)
125+
if translated_text is None:
126+
continue
127+
128+
translated = True
129+
130+
entry.msgstr = translated_text
131+
# update_po_translation(po, english_text, translated_text)
132+
133+
if translated:
134+
po.save(pofilename)

.migration/tutorialpyar

Submodule tutorialpyar added at e2b1222

0 commit comments

Comments
 (0)