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

Appearance settings

Script rst2po.py to migrate tutorial.python.org.ar to this new version #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
May 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3be6970
Tutorial PyAr submodule
humitos May 2, 2020
f71c1fd
rst2po.py
humitos May 2, 2020
3951c61
Skel for the rst2po.py script
humitos May 2, 2020
3cea73b
Merge branch '3.7' into rst2po
humitos May 2, 2020
8cbe9ed
About to start the (english, spanish) mapping list
humitos May 2, 2020
a274828
Merge branch '3.7' of github.com:raulcd/python-docs-es into rst2po
humitos May 2, 2020
5e07374
Merge branch 'rst2po' of github.com:raulcd/python-docs-es into rst2po
humitos May 2, 2020
25b5aa7
Initial working version of rst2po.py
humitos May 2, 2020
9ff4f8c
Only save translated files
humitos May 2, 2020
cfb3344
Use tutorialpyar with fixes
humitos May 2, 2020
4a30a79
First pass reviewed
humitos May 2, 2020
7f679cf
ignore ! when comparing
gilgamezh May 2, 2020
5144e29
update translation
gilgamezh May 2, 2020
d7569d2
More translations
humitos May 2, 2020
ae92662
Merge branch 'rst2po' of github.com:raulcd/python-docs-es into rst2po
humitos May 2, 2020
72b4d3d
More inputoutput
humitos May 2, 2020
cf3a545
update datastructures.po translation (migration)
gilgamezh May 2, 2020
08e56cc
Update tutorialpyar submodule
humitos May 2, 2020
2b39104
update datastructures.po translation (migration)
gilgamezh May 2, 2020
7e9682c
update datastructures.po translation (migration)
gilgamezh May 2, 2020
5ba9b04
Merge branch 'rst2po' of github.com:raulcd/python-docs-es into rst2po
gilgamezh May 2, 2020
bfc7aec
Classes
humitos May 2, 2020
2a7a07f
Update tutorialpyar with fixes
humitos May 2, 2020
81a7350
Merge branch 'rst2po' of github.com:raulcd/python-docs-es into rst2po
humitos May 2, 2020
76368ac
Translate errors.po
humitos May 2, 2020
0dc54d5
modules.po
humitos May 2, 2020
a4d592e
stdlib.po translated from pyar tutorial
humitos May 2, 2020
3b5c9d0
update stdlib2 translation (migration)
gilgamezh May 2, 2020
edd1505
update stdlib2 translation (migration)
gilgamezh May 2, 2020
322f1a7
update submodule
gilgamezh May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
About to start the (english, spanish) mapping list
  • Loading branch information
humitos committed May 2, 2020
commit 8cbe9ed9feb4488b83a76afd875f3ef7ae55705f
54 changes: 48 additions & 6 deletions 54 .migration/rst2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# and there is no translation for that sentence/paragraph it updates the .po file with the translated text
# from the .rst file.

import re
import glob
import os
import polib # fades
Expand All @@ -17,17 +18,55 @@
'..',
))

RST_DIR = os.path.abspath(
RST_TRADUCIDOS_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'tutorialpyar',
'traducidos',
))

RST_ORIGINAL_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'tutorialpyar',
'original',
))



def get_rst_file(pofilename):
"""Given a .po filename returns the corresponding .rst filename"""
pass
basename = os.path.basename(pofilename)
basename, ext = basename.split('.')
rstfilename = os.path.join(RST_TRADUCIDOS_DIR, f'{basename}.rst')
if os.path.exists(rstfilename):
return rstfilename


def get_rst_original_filename(rstfilename):
if rstfilename.endswith('real-index.rst'):
rst_original_filename = 'index.rst'

rst_original_filename = os.path.join(RST_ORIGINAL_DIR, rst_original_filename)
if os.path.exists(rst_original_filename):
return rst_original_filename


def create_english_spanish_sentences(rstfilename):
"""Create a tuple of (english, spanish) sentences for rstfilename"""

# NOTE: we could use docutils and parse the rst in the correct way, but
# that will probably take more time

with open(rstfilename) as fd:
lines = []
for line in fd.read().splitlines():
if re.match('^[a-zA-Z] ', line):
# keep text lines only
lines.append(line)
# make the document just one line so we can split it in sentences
document = ' '.join(lines)
import pdb; pdb.set_trace()


def get_rst_translation_text(rstfilename, text):
Expand All @@ -40,12 +79,13 @@ def update_po_translation(pofilename, english, spanish):
pass



for pofilename in glob.glob(PO_DIR + '**/*.po'):
for pofilename in glob.glob(PO_DIR + '**/*/*.po'):
rstfilename = get_rst_file(pofilename)
if rst is None:
if rstfilename is None:
continue

create_english_spanish_sentences(rstfilename)

po = polib.pofile(pofilename)
for entry in po:
english_text = entry.msgid
Expand All @@ -58,4 +98,6 @@ def update_po_translation(pofilename, english, spanish):
if translated_text is None:
continue

update_po_translation(po, english_text, translated_text)
entry.msgstr = translated_text
# update_po_translation(po, english_text, translated_text)
po.save(pofilename)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.