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
f1f76a9a
Commit
f1f76a9a
authored
Dec 20, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dummy text has more accents, and properly ignored more non-text things.
parent
5e244b1c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
15 deletions
+32
-15
i18n/converter.py
+10
-1
i18n/dummy.py
+5
-2
i18n/tests/test_converter.py
+7
-3
i18n/tests/test_dummy.py
+10
-9
No files found.
i18n/converter.py
View file @
f1f76a9a
...
@@ -20,7 +20,16 @@ class Converter(object):
...
@@ -20,7 +20,16 @@ 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'(<[-\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
):
def
convert
(
self
,
string
):
"""Returns: a converted tagged string
"""Returns: a converted tagged string
...
...
i18n/dummy.py
View file @
f1f76a9a
...
@@ -34,8 +34,11 @@ TABLE = {'A': u'\xC0',
...
@@ -34,8 +34,11 @@ TABLE = {'A': u'\xC0',
'I'
:
U'
\xCC
'
,
'I'
:
U'
\xCC
'
,
'i'
:
u'
\xEF
'
,
'i'
:
u'
\xEF
'
,
'O'
:
u'
\xD8
'
,
'O'
:
u'
\xD8
'
,
'o'
:
u'
\xF6
'
,
'o'
:
u'
\xF8
'
,
'u'
:
u'
\xFC
'
'U'
:
u'
\xDB
'
,
'u'
:
u'
\xFC
'
,
'Y'
:
u'
\xDD
'
,
'y'
:
u'
\xFD
'
,
}
}
...
...
i18n/tests/test_converter.py
View file @
f1f76a9a
...
@@ -22,7 +22,7 @@ class TestConverter(TestCase):
...
@@ -22,7 +22,7 @@ class TestConverter(TestCase):
Assert that embedded HTML and python tags are not converted.
Assert that embedded HTML and python tags are not converted.
"""
"""
c
=
UpcaseConverter
()
c
=
UpcaseConverter
()
test_cases
=
(
test_cases
=
[
# no tags
# no tags
(
'big bad wolf'
,
'BIG BAD WOLF'
),
(
'big bad wolf'
,
'BIG BAD WOLF'
),
# one html tag
# one html tag
...
@@ -36,7 +36,11 @@ class TestConverter(TestCase):
...
@@ -36,7 +36,11 @@ class TestConverter(TestCase):
# both kinds of tags
# both kinds of tags
(
'<strong>big</strong>
%(adjective)
s
%(noun)
s'
,
(
'<strong>big</strong>
%(adjective)
s
%(noun)
s'
,
'<strong>BIG</strong>
%(adjective)
s
%(noun)
s'
),
'<strong>BIG</strong>
%(adjective)
s
%(noun)
s'
),
)
# .format-style tags
for
(
source
,
expected
)
in
test_cases
:
(
'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
)
result
=
c
.
convert
(
source
)
self
.
assertEquals
(
result
,
expected
)
self
.
assertEquals
(
result
,
expected
)
i18n/tests/test_dummy.py
View file @
f1f76a9a
...
@@ -18,23 +18,24 @@ class TestDummy(TestCase):
...
@@ -18,23 +18,24 @@ class TestDummy(TestCase):
Tests with a dummy converter (adds spurious accents to strings).
Tests with a dummy converter (adds spurious accents to strings).
Assert that embedded HTML and python tags are not converted.
Assert that embedded HTML and python tags are not converted.
"""
"""
test_cases
=
((
"hello my name is Bond, James Bond"
,
test_cases
=
[
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#'
),
(
"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>'
,
(
'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#'
),
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'
,
(
'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#"
)
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
:
for
source
,
expected
in
test_cases
:
result
=
self
.
converter
.
convert
(
source
)
result
=
self
.
converter
.
convert
(
source
)
self
.
assertEquals
(
result
,
expected
)
self
.
assertEquals
(
result
,
expected
)
def
test_singular
(
self
):
def
test_singular
(
self
):
entry
=
POEntry
()
entry
=
POEntry
()
entry
.
msgid
=
'A lovely day for a cup of tea.'
entry
.
msgid
=
'A lovely day for a cup of tea.'
expected
=
u'
\xc0
l
\xf
6
v
\xe9
ly d
\xe4
y f
\xf6
r
\xe4
\xe7\xfc
p
\xf6
f t
\xe9\xe4
. Lorem i#'
expected
=
u'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4\xfd
f
\xf8
r
\xe4
\xe7\xfc
p
\xf8
f t
\xe9\xe4
. Lorem i#'
self
.
converter
.
convert_msg
(
entry
)
self
.
converter
.
convert_msg
(
entry
)
self
.
assertEquals
(
entry
.
msgstr
,
expected
)
self
.
assertEquals
(
entry
.
msgstr
,
expected
)
...
@@ -42,8 +43,8 @@ class TestDummy(TestCase):
...
@@ -42,8 +43,8 @@ class TestDummy(TestCase):
entry
=
POEntry
()
entry
=
POEntry
()
entry
.
msgid
=
'A lovely day for a cup of tea.'
entry
.
msgid
=
'A lovely day for a cup of tea.'
entry
.
msgid_plural
=
'A lovely day for some cups of tea.'
entry
.
msgid_plural
=
'A lovely day for some cups of tea.'
expected_s
=
u'
\xc0
l
\xf
6
v
\xe9
ly d
\xe4
y f
\xf6
r
\xe4
\xe7\xfc
p
\xf6
f t
\xe9\xe4
. Lorem i#'
expected_s
=
u'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4\xfd
f
\xf8
r
\xe4
\xe7\xfc
p
\xf8
f t
\xe9\xe4
. Lorem i#'
expected_p
=
u'
\xc0
l
\xf
6
v
\xe9
ly d
\xe4
y f
\xf6
r s
\xf6
m
\xe9
\xe7\xfc
ps
\xf6
f t
\xe9\xe4
. Lorem ip#'
expected_p
=
u'
\xc0
l
\xf
8
v
\xe9
l
\xfd
d
\xe4\xfd
f
\xf8
r s
\xf8
m
\xe9
\xe7\xfc
ps
\xf8
f t
\xe9\xe4
. Lorem ip#'
self
.
converter
.
convert_msg
(
entry
)
self
.
converter
.
convert_msg
(
entry
)
result
=
entry
.
msgstr_plural
result
=
entry
.
msgstr_plural
self
.
assertEquals
(
result
[
'0'
],
expected_s
)
self
.
assertEquals
(
result
[
'0'
],
expected_s
)
...
...
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