Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
c08a73f0
Commit
c08a73f0
authored
Mar 13, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8
parent
561ecc76
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
15 deletions
+28
-15
i18n/converter.py
+5
-4
i18n/execute.py
+4
-1
i18n/extract.py
+18
-10
i18n/validate.py
+1
-0
No files found.
i18n/converter.py
View file @
c08a73f0
import
re
import
re
import
itertools
import
itertools
class
Converter
(
object
):
class
Converter
(
object
):
"""Converter is an abstract class that transforms strings.
"""Converter is an abstract class that transforms strings.
It hides embedded tags (HTML or Python sequences) from transformation
It hides embedded tags (HTML or Python sequences) from transformation
...
@@ -20,7 +21,8 @@ class Converter(object):
...
@@ -20,7 +21,8 @@ class Converter(object):
# matches tags like these:
# matches tags like these:
# HTML: <B>, </B>, <BR/>, <textformat leading="10">
# HTML: <B>, </B>, <BR/>, <textformat leading="10">
# Python: %(date)s, %(name)s
# Python: %(date)s, %(name)s
tag_pattern
=
re
.
compile
(
r'''
tag_pattern
=
re
.
compile
(
r'''
(<[^>]+>) | # <tag>
(<[^>]+>) | # <tag>
({[^}]+}) | # {tag}
({[^}]+}) | # {tag}
(
%
\([\w]+\)\w) | #
%(tag)
s
(
%
\([\w]+\)\w) | #
%(tag)
s
...
@@ -28,7 +30,7 @@ class Converter(object):
...
@@ -28,7 +30,7 @@ class Converter(object):
(&\#\d+;) | # Ӓ
(&\#\d+;) | # Ӓ
(&\#x[0-9a-f]+;) # ꯍ
(&\#x[0-9a-f]+;) # ꯍ
'''
,
'''
,
re
.
IGNORECASE
|
re
.
VERBOSE
re
.
IGNORECASE
|
re
.
VERBOSE
)
)
def
convert
(
self
,
string
):
def
convert
(
self
,
string
):
...
@@ -55,7 +57,7 @@ class Converter(object):
...
@@ -55,7 +57,7 @@ class Converter(object):
tags
=
[
''
.
join
(
tag
)
for
tag
in
tags
]
tags
=
[
''
.
join
(
tag
)
for
tag
in
tags
]
(
new
,
nfound
)
=
self
.
tag_pattern
.
subn
(
count
,
string
)
(
new
,
nfound
)
=
self
.
tag_pattern
.
subn
(
count
,
string
)
if
len
(
tags
)
!=
nfound
:
if
len
(
tags
)
!=
nfound
:
raise
Exception
(
'tags dont match:'
+
string
)
raise
Exception
(
'tags dont match:'
+
string
)
return
(
new
,
tags
)
return
(
new
,
tags
)
def
retag_string
(
self
,
string
,
tags
):
def
retag_string
(
self
,
string
,
tags
):
...
@@ -65,7 +67,6 @@ class Converter(object):
...
@@ -65,7 +67,6 @@ class Converter(object):
string
=
re
.
sub
(
p
,
tag
,
string
,
1
)
string
=
re
.
sub
(
p
,
tag
,
string
,
1
)
return
string
return
string
# ------------------------------
# ------------------------------
# Customize this in subclasses of Converter
# Customize this in subclasses of Converter
...
...
i18n/execute.py
View file @
c08a73f0
import
os
,
subprocess
,
logging
import
os
import
subprocess
import
logging
from
i18n.config
import
BASE_DIR
from
i18n.config
import
BASE_DIR
LOG
=
logging
.
getLogger
(
__name__
)
LOG
=
logging
.
getLogger
(
__name__
)
def
execute
(
command
,
working_directory
=
BASE_DIR
,
stderr
=
subprocess
.
STDOUT
):
def
execute
(
command
,
working_directory
=
BASE_DIR
,
stderr
=
subprocess
.
STDOUT
):
"""
"""
Executes shell command in a given working_directory.
Executes shell command in a given working_directory.
...
...
i18n/extract.py
View file @
c08a73f0
...
@@ -35,6 +35,7 @@ EDX_MARKER = "edX translation file"
...
@@ -35,6 +35,7 @@ EDX_MARKER = "edX translation file"
LOG
=
logging
.
getLogger
(
__name__
)
LOG
=
logging
.
getLogger
(
__name__
)
DEVNULL
=
open
(
os
.
devnull
,
'wb'
)
DEVNULL
=
open
(
os
.
devnull
,
'wb'
)
def
base
(
path1
,
*
paths
):
def
base
(
path1
,
*
paths
):
"""Return a relative path from BASE_DIR to path1 / paths[0] / ... """
"""Return a relative path from BASE_DIR to path1 / paths[0] / ... """
return
BASE_DIR
.
relpathto
(
path1
.
joinpath
(
*
paths
))
return
BASE_DIR
.
relpathto
(
path1
.
joinpath
(
*
paths
))
...
@@ -143,20 +144,24 @@ def fix_header(po):
...
@@ -143,20 +144,24 @@ def fix_header(po):
fixes
=
(
fixes
=
(
(
'SOME DESCRIPTIVE TITLE'
,
EDX_MARKER
),
(
'SOME DESCRIPTIVE TITLE'
,
EDX_MARKER
),
(
'Translations template for PROJECT.'
,
EDX_MARKER
),
(
'Translations template for PROJECT.'
,
EDX_MARKER
),
(
'YEAR'
,
'
%
s'
%
datetime
.
utcnow
()
.
year
),
(
'YEAR'
,
str
(
datetime
.
utcnow
()
.
year
)
),
(
'ORGANIZATION'
,
'edX'
),
(
'ORGANIZATION'
,
'edX'
),
(
"THE PACKAGE'S COPYRIGHT HOLDER"
,
"EdX"
),
(
"THE PACKAGE'S COPYRIGHT HOLDER"
,
"EdX"
),
(
'This file is distributed under the same license as the PROJECT project.'
,
(
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
),
'This file is distributed under the same license as the PROJECT project.'
,
(
'This file is distributed under the same license as the PACKAGE package.'
,
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
),
),
(
'FIRST AUTHOR <EMAIL@ADDRESS>'
,
(
'EdX Team <info@edx.org>'
)
'This file is distributed under the same license as the PACKAGE package.'
,
)
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
),
(
'FIRST AUTHOR <EMAIL@ADDRESS>'
,
'EdX Team <info@edx.org>'
),
)
for
src
,
dest
in
fixes
:
for
src
,
dest
in
fixes
:
header
=
header
.
replace
(
src
,
dest
)
header
=
header
.
replace
(
src
,
dest
)
po
.
header
=
header
po
.
header
=
header
def
fix_metadata
(
po
):
def
fix_metadata
(
po
):
"""
"""
Replace default metadata with edX metadata
Replace default metadata with edX metadata
...
@@ -179,12 +184,13 @@ def fix_metadata(po):
...
@@ -179,12 +184,13 @@ def fix_metadata(po):
'PO-Revision-Date'
:
datetime
.
utcnow
(),
'PO-Revision-Date'
:
datetime
.
utcnow
(),
'Report-Msgid-Bugs-To'
:
'openedx-translation@googlegroups.com'
,
'Report-Msgid-Bugs-To'
:
'openedx-translation@googlegroups.com'
,
'Project-Id-Version'
:
'0.1a'
,
'Project-Id-Version'
:
'0.1a'
,
'Language'
:
'en'
,
'Language'
:
'en'
,
'Last-Translator'
:
''
,
'Last-Translator'
:
''
,
'Language-Team'
:
'openedx-translation <openedx-translation@googlegroups.com>'
,
'Language-Team'
:
'openedx-translation <openedx-translation@googlegroups.com>'
,
}
}
po
.
metadata
.
update
(
fixes
)
po
.
metadata
.
update
(
fixes
)
def
strip_key_strings
(
po
):
def
strip_key_strings
(
po
):
"""
"""
Removes all entries in PO which are key strings.
Removes all entries in PO which are key strings.
...
@@ -194,6 +200,7 @@ def strip_key_strings(po):
...
@@ -194,6 +200,7 @@ def strip_key_strings(po):
del
po
[:]
del
po
[:]
po
+=
newlist
po
+=
newlist
def
is_key_string
(
string
):
def
is_key_string
(
string
):
"""
"""
returns True if string is a key string.
returns True if string is a key string.
...
@@ -201,6 +208,7 @@ def is_key_string(string):
...
@@ -201,6 +208,7 @@ def is_key_string(string):
"""
"""
return
len
(
string
)
>
1
and
string
[
0
]
==
'_'
return
len
(
string
)
>
1
and
string
[
0
]
==
'_'
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--verbose'
,
'-v'
,
action
=
'count'
,
default
=
0
)
parser
.
add_argument
(
'--verbose'
,
'-v'
,
action
=
'count'
,
default
=
0
)
...
...
i18n/validate.py
View file @
c08a73f0
...
@@ -16,6 +16,7 @@ from i18n.converter import Converter
...
@@ -16,6 +16,7 @@ from i18n.converter import Converter
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
validate_po_files
(
root
,
report_empty
=
False
):
def
validate_po_files
(
root
,
report_empty
=
False
):
"""
"""
Validate all of the po files found in the root directory.
Validate all of the po files found in the root directory.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment