Skip to content

Commit 3951c61

Browse files
committed
Skel for the rst2po.py script
1 parent f71c1fd commit 3951c61

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.migration/rst2po.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,56 @@
66
# and there is no translation for that sentence/paragraph it updates the .po file with the translated text
77
# from the .rst file.
88

9+
import glob
10+
import os
911
import polib # fades
12+
13+
14+
PO_DIR = os.path.abspath(
15+
os.path.join(
16+
os.path.dirname(__file__),
17+
'..',
18+
))
19+
20+
RST_DIR = os.path.abspath(
21+
os.path.join(
22+
os.path.dirname(__file__),
23+
'tutorialpyar',
24+
))
25+
26+
27+
28+
def get_rst_file(pofilename):
29+
"""Given a .po filename returns the corresponding .rst filename"""
30+
pass
31+
32+
33+
def get_rst_translation_text(rstfilename, text):
34+
"""Given an rstfilename an a text returns the corresponding translated text if exists"""
35+
pass
36+
37+
38+
def update_po_translation(pofilename, english, spanish):
39+
"""Update the pofilename with the translated spanish text"""
40+
pass
41+
42+
43+
44+
for pofilename in glob.glob(PO_DIR + '**/*.po'):
45+
rstfilename = get_rst_file(pofilename)
46+
if rst is None:
47+
continue
48+
49+
po = polib.pofile(pofilename)
50+
for entry in po:
51+
english_text = entry.msgid
52+
spanish_text = entry.msgstr
53+
if spanish_text:
54+
# Do not override already translated text
55+
continue
56+
57+
translated_text = get_rst_translation_text(rstfilename, english_text)
58+
if translated_text is None:
59+
continue
60+
61+
update_po_translation(po, english_text, translated_text)

0 commit comments

Comments
 (0)