Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
f1f76a9a
Commit
f1f76a9a
authored
11 years ago
by
Ned Batchelder
Browse files
Options
Downloads
Patches
Plain Diff
Dummy text has more accents, and properly ignored more non-text things.
parent
5e244b1c
Loading
Loading
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
i18n/converter.py
+10
-1
10 additions, 1 deletion
i18n/converter.py
i18n/dummy.py
+5
-2
5 additions, 2 deletions
i18n/dummy.py
i18n/tests/test_converter.py
+7
-3
7 additions, 3 deletions
i18n/tests/test_converter.py
i18n/tests/test_dummy.py
+14
-13
14 additions, 13 deletions
i18n/tests/test_dummy.py
with
36 additions
and
19 deletions
i18n/converter.py
+
10
−
1
View file @
f1f76a9a
...
...
@@ -20,7 +20,16 @@ class Converter(object):
# matches tags like these:
# HTML: <B>, </B>, <BR/>, <textformat leading="10">
# Python: %(date)s, %(name)s
tag_pattern
=
re
.
compile
(
r
'
(<[-\w
"
.:?=/]*>)|({[^}]*})|(%\([^)]*\)\w)
'
,
re
.
I
)
tag_pattern
=
re
.
compile
(
r
'''
(<[-\w
"
.:?=/]*>) | # <tag>
({[^}]*}) | # {tag}
(%\([^)]*\)\w) | # %(tag)s
(&\w+;) | # &entity;
(&\#\d+;) | # Ӓ
(&\#x[0-9a-f]+;) # ꯍ
'''
,
re
.
IGNORECASE
|
re
.
VERBOSE
)
def
convert
(
self
,
string
):
"""
Returns: a converted tagged string
...
...
This diff is collapsed.
Click to expand it.
i18n/dummy.py
+
5
−
2
View file @
f1f76a9a
...
...
@@ -34,8 +34,11 @@ TABLE = {'A': u'\xC0',
'
I
'
:
U
'
\xCC
'
,
'
i
'
:
u
'
\xEF
'
,
'
O
'
:
u
'
\xD8
'
,
'
o
'
:
u
'
\xF6
'
,
'
u
'
:
u
'
\xFC
'
'
o
'
:
u
'
\xF8
'
,
'
U
'
:
u
'
\xDB
'
,
'
u
'
:
u
'
\xFC
'
,
'
Y
'
:
u
'
\xDD
'
,
'
y
'
:
u
'
\xFD
'
,
}
...
...
This diff is collapsed.
Click to expand it.
i18n/tests/test_converter.py
+
7
−
3
View file @
f1f76a9a
...
...
@@ -22,7 +22,7 @@ class TestConverter(TestCase):
Assert that embedded HTML and python tags are not converted.
"""
c
=
UpcaseConverter
()
test_cases
=
(
test_cases
=
[
# no tags
(
'
big bad wolf
'
,
'
BIG BAD WOLF
'
),
# one html tag
...
...
@@ -36,7 +36,11 @@ class TestConverter(TestCase):
# both kinds of tags
(
'
<strong>big</strong> %(adjective)s %(noun)s
'
,
'
<strong>BIG</strong> %(adjective)s %(noun)s
'
),
)
for
(
source
,
expected
)
in
test_cases
:
# .format-style tags
(
'
The {0} barn is {1!r}.
'
,
'
THE {0} BARN IS {1!r}.
'
),
# HTML entities
(
'
<b>© 2013 edX,  </b>
'
,
'
<b>© 2013 EDX,  </b>
'
),
]
for
source
,
expected
in
test_cases
:
result
=
c
.
convert
(
source
)
self
.
assertEquals
(
result
,
expected
)
This diff is collapsed.
Click to expand it.
i18n/tests/test_dummy.py
+
14
−
13
View file @
f1f76a9a
...
...
@@ -18,23 +18,24 @@ class TestDummy(TestCase):
Tests with a dummy converter (adds spurious accents to strings).
Assert that embedded HTML and python tags are not converted.
"""
test_cases
=
((
"
hello my name is Bond, James Bond
"
,
u
'
h
\xe9
ll
\xf6
my n
\xe4
m
\xe9
\xef
s B
\xf6
nd, J
\xe4
m
\xe9
s B
\xf6
nd Lorem i#
'
),
(
'
don
\'
t convert <a href=
"
href
"
>tag ids</a>
'
,
u
'
d
\xf6
n
\'
t
\xe7\xf6
nv
\xe9
rt <a href=
"
href
"
>t
\xe4
g
\xef
ds</a> Lorem ipsu#
'
),
(
'
don
\'
t convert %(name)s tags on %(date)s
'
,
u
"
d
\xf6
n
'
t
\xe7\xf6
nv
\xe9
rt %(name)s t
\xe4
gs
\xf6
n %(date)s Lorem ips#
"
)
)
for
(
source
,
expected
)
in
test_cases
:
test_cases
=
[
(
"
hello my name is Bond, James Bond
"
,
u
'
h
\xe9
ll
\xf8
m
\xfd
n
\xe4
m
\xe9
\xef
s B
\xf8
nd, J
\xe4
m
\xe9
s B
\xf8
nd Lorem i#
'
),
(
'
don
\'
t convert <a href=
"
href
"
>tag ids</a>
'
,
u
'
d
\xf8
n
\'
t
\xe7\xf8
nv
\xe9
rt <a href=
"
href
"
>t
\xe4
g
\xef
ds</a> Lorem ipsu#
'
),
(
'
don
\'
t convert %(name)s tags on %(date)s
'
,
u
"
d
\xf8
n
'
t
\xe7\xf8
nv
\xe9
rt %(name)s t
\xe4
gs
\xf8
n %(date)s Lorem ips#
"
)
]
for
source
,
expected
in
test_cases
:
result
=
self
.
converter
.
convert
(
source
)
self
.
assertEquals
(
result
,
expected
)
def
test_singular
(
self
):
entry
=
POEntry
()
entry
.
msgid
=
'
A lovely day for a cup of tea.
'
expected
=
u
'
\xc0
l
\xf
6
v
\xe9
l
y
d
\xe4
y
f
\xf
6
r
\xe4
\xe7\xfc
p
\xf
6
f t
\xe9\xe4
. Lorem i#
'
expected
=
u
'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4
\xfd
f
\xf
8
r
\xe4
\xe7\xfc
p
\xf
8
f t
\xe9\xe4
. Lorem i#
'
self
.
converter
.
convert_msg
(
entry
)
self
.
assertEquals
(
entry
.
msgstr
,
expected
)
...
...
@@ -42,8 +43,8 @@ class TestDummy(TestCase):
entry
=
POEntry
()
entry
.
msgid
=
'
A lovely day for a cup of tea.
'
entry
.
msgid_plural
=
'
A lovely day for some cups of tea.
'
expected_s
=
u
'
\xc0
l
\xf
6
v
\xe9
l
y
d
\xe4
y
f
\xf
6
r
\xe4
\xe7\xfc
p
\xf
6
f t
\xe9\xe4
. Lorem i#
'
expected_p
=
u
'
\xc0
l
\xf
6
v
\xe9
l
y
d
\xe4
y
f
\xf
6
r s
\xf
6
m
\xe9
\xe7\xfc
ps
\xf
6
f t
\xe9\xe4
. Lorem ip#
'
expected_s
=
u
'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4
\xfd
f
\xf
8
r
\xe4
\xe7\xfc
p
\xf
8
f t
\xe9\xe4
. Lorem i#
'
expected_p
=
u
'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4
\xfd
f
\xf
8
r s
\xf
8
m
\xe9
\xe7\xfc
ps
\xf
8
f t
\xe9\xe4
. Lorem ip#
'
self
.
converter
.
convert_msg
(
entry
)
result
=
entry
.
msgstr_plural
self
.
assertEquals
(
result
[
'
0
'
],
expected_s
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment