Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-docs-es/.migration/rst2po.py at pythonversion-sphinx-variable · python/python-docs-es · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
python-docs-es
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
412
Star
368
Code
Issues
423
Pull requests
17
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Files
Expand file tree
pythonversion-sphinx-variable
Breadcrumbs
python-docs-es
/
.migration
/
rst2po.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
134 lines (102 loc) · 3.84 KB
pythonversion-sphinx-variable
Breadcrumbs
python-docs-es
/
.migration
/
rst2po.py
Copy path
Top
File metadata and controls
Code
Blame
134 lines (102 loc) · 3.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# rst2po.py
# Script to migrate the Python official tutorial that we have already translated in PyAr
# (https://github.com/PyAr/tutorial) from reStructuredText to the new official translation format (.po)
#
# It parses the .rst and compare sentence/paragraph by sentence/paragraph and if the match is exact,
# 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
PO_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
))
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"""
basename
=
os
.
path
.
basename
(
pofilename
)
basename
,
ext
=
basename
.
rsplit
(
'.'
,
1
)
rstfilename
=
os
.
path
.
join
(
RST_TRADUCIDOS_DIR
,
f'
{
basename
}
.rst'
)
if
os
.
path
.
exists
(
rstfilename
):
return
rstfilename
def
get_rst_original_filename
(
rstfilename
):
rst_original_filename
=
''
if
rstfilename
.
endswith
(
'real-index.rst'
):
rst_original_filename
=
'index.rst'
basename
=
os
.
path
.
basename
(
rst_original_filename
or
rstfilename
)
rst_original_filename
=
os
.
path
.
join
(
RST_ORIGINAL_DIR
,
basename
)
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"""
def
get_paragraph
(
fd
):
lines
=
[]
paragraph
=
[]
for
line
in
fd
.
read
().
splitlines
():
# import pdb; pdb.set_trace()
if
any
([
line
.
startswith
(
'.. '
),
line
.
startswith
(
'==='
),
line
.
startswith
(
'---'
),
line
.
startswith
(
'***'
),
]):
continue
if
line
==
''
and
not
paragraph
:
continue
if
line
==
''
:
lines
.
append
(
' '
.
join
(
paragraph
))
paragraph
=
[]
continue
paragraph
.
append
(
line
)
return
lines
# NOTE: we could use docutils and parse the rst in the correct way, but
# that will probably take more time
with
open
(
get_rst_original_filename
(
rstfilename
))
as
fd
:
english
=
get_paragraph
(
fd
)
with
open
(
rstfilename
)
as
fd
:
spanish
=
get_paragraph
(
fd
)
result
=
list
(
zip
(
english
,
spanish
))
return
result
def
get_rst_translation_text
(
rstfilename
,
english_spanish
,
text
):
"""Given an rstfilename an a text returns the corresponding translated text if exists"""
for
en
,
es
in
english_spanish
:
if
en
.
replace
(
"!"
,
""
)
==
text
.
replace
(
"!"
,
""
):
return
es
def
update_po_translation
(
pofilename
,
english
,
spanish
):
"""Update the pofilename with the translated spanish text"""
pass
for
pofilename
in
glob
.
glob
(
PO_DIR
+
'**/*/*.po'
):
translated
=
False
rstfilename
=
get_rst_file
(
pofilename
)
if
rstfilename
is
None
:
continue
english_spanish
=
create_english_spanish_sentences
(
rstfilename
)
po
=
polib
.
pofile
(
pofilename
)
for
entry
in
po
:
english_text
=
entry
.
msgid
spanish_text
=
entry
.
msgstr
if
spanish_text
:
# Do not override already translated text
continue
translated_text
=
get_rst_translation_text
(
rstfilename
,
english_spanish
,
english_text
)
if
translated_text
is
None
:
continue
translated
=
True
entry
.
msgstr
=
translated_text
# update_po_translation(po, english_text, translated_text)
if
translated
:
po
.
save
(
pofilename
)
You can’t perform that action at this time.