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
b06cf9cf
Commit
b06cf9cf
authored
11 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Make i18n tests work with a clean checkout
parent
f5ffc94d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
i18n/dummy.py
+91
-23
91 additions, 23 deletions
i18n/dummy.py
i18n/make_dummy.py
+0
-66
0 additions, 66 deletions
i18n/make_dummy.py
i18n/tests/test_generate.py
+9
-2
9 additions, 2 deletions
i18n/tests/test_generate.py
rakelib/i18n.rake
+1
-1
1 addition, 1 deletion
rakelib/i18n.rake
with
101 additions
and
92 deletions
i18n/dummy.py
+
91
−
23
View file @
b06cf9cf
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r
"""
Creates new localization properties files in a dummy language.
Each property file is derived from the equivalent en_US file, with these
trans
form
ation
s applied:
"""
Generate test
trans
l
ation
files from human-readable po files.
1. Every vowel is replaced with an equivalent with extra accent marks.
Dummy language is specified in configuration file (see config.py)
two letter language codes reference:
see http://www.loc.gov/standards/iso639-2/php/code_list.php
2. Every string is padded out to +30% length to simulate verbose languages
(such as German) to see if layout and flows work properly.
Django will not localize in languages that django itself has not been
localized for. So we are using a well-known language (default=
'
eo
'
).
Django languages are listed in django.conf.global_settings.LANGUAGES
3. Every string is terminated with a
'
#
'
character to make it easier to detect
truncation.
po files can be generated with this:
django-admin.py makemessages --all --extension html -l en
Example use:
:
Usage
:
>>>
from
dummy
import
Dummy
>>>
c
=
Dummy
()
>>>
c
.
convert
(
"
My name is Bond, James Bond
"
)
u
'
M
\xfd
n
\xe4
m
\xe9
\xef
s B
\xf8
nd, J
\xe4
m
\xe9
s B
\xf8
nd
\u2360\u03c3\u044f\u0454\u043c
\u03b9\u03c1
#
'
>>>
print
c
.
convert
(
"
My name is Bond, James Bond
"
)
Mý
nämé
ïs
Bønd
,
Jämés
Bønd
Ⱡσяєм
ιρ
#
>>>
print
c
.
convert
(
"
don
'
t convert <a href=
'
href
'
>tag ids</a>
"
)
døn
'
t çønvért <a href=
'
href
'
>täg ïds</a> Ⱡσяєм ιρѕυ#
>>>
print
c
.
convert
(
"
don
'
t convert %(name)s tags on %(date)s
"
)
døn
'
t çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#
$ ./dummy.py
generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES,
where $DUMMY_LOCALE is the dummy_locale value set in the i18n config
"""
import
os
import
polib
from
i18n.config
import
CONFIGURATION
from
i18n.execute
import
create_dir_if_necessary
from
i18n.converter
import
Converter
# Substitute plain characters with accented lookalikes.
...
...
@@ -74,10 +74,32 @@ PAD_FACTOR = 1.33
class
Dummy
(
Converter
):
"""
A string converter that generates dummy strings with fake accents
and lorem ipsum padding.
r
"""
Creates new localization properties files in a dummy language.
Each property file is derived from the equivalent en_US file, with these
transformations applied:
1. Every vowel is replaced with an equivalent with extra accent marks.
2. Every string is padded out to +30% length to simulate verbose languages
(such as German) to see if layout and flows work properly.
3. Every string is terminated with a
'
#
'
character to make it easier to detect
truncation.
Example use::
>>>
from
dummy
import
Dummy
>>>
c
=
Dummy
()
>>>
c
.
convert
(
"
My name is Bond, James Bond
"
)
u
'
M
\xfd
n
\xe4
m
\xe9
\xef
s B
\xf8
nd, J
\xe4
m
\xe9
s B
\xf8
nd
\u2360\u03c3\u044f\u0454\u043c
\u03b9\u03c1
#
'
>>>
print
c
.
convert
(
"
My name is Bond, James Bond
"
)
Mý
nämé
ïs
Bønd
,
Jämés
Bønd
Ⱡσяєм
ιρ
#
>>>
print
c
.
convert
(
"
don
'
t convert <a href=
'
href
'
>tag ids</a>
"
)
døn
'
t çønvért <a href=
'
href
'
>täg ïds</a> Ⱡσяєм ιρѕυ#
>>>
print
c
.
convert
(
"
don
'
t convert %(name)s tags on %(date)s
"
)
døn
'
t çønvért %(name)s tägs øn %(date)s Ⱡσяєм ιρѕ#
"""
def convert(self, string):
result = Converter.convert(self, string)
...
...
@@ -134,3 +156,49 @@ class Dummy(Converter):
if
original
[
-
1
]
==
'
\n
'
and
translated
[
-
1
]
!=
'
\n
'
:
translated
+=
'
\n
'
return
translated
def
make_dummy
(
file
,
locale
):
"""
Takes a source po file, reads it, and writes out a new po file
in :param locale: containing a dummy translation.
"""
if
not
os
.
path
.
exists
(
file
):
raise
IOError
(
'
File does not exist: %s
'
%
file
)
pofile
=
polib
.
pofile
(
file
)
converter
=
Dummy
()
for
msg
in
pofile
:
converter
.
convert_msg
(
msg
)
# Apply declaration for English pluralization rules so that ngettext will
# do something reasonable.
pofile
.
metadata
[
'
Plural-Forms
'
]
=
'
nplurals=2; plural=(n != 1);
'
new_file
=
new_filename
(
file
,
locale
)
create_dir_if_necessary
(
new_file
)
pofile
.
save
(
new_file
)
def
new_filename
(
original_filename
,
new_locale
):
"""
Returns a filename derived from original_filename, using new_locale as the locale
"""
orig_dir
=
os
.
path
.
dirname
(
original_filename
)
msgs_dir
=
os
.
path
.
basename
(
orig_dir
)
orig_file
=
os
.
path
.
basename
(
original_filename
)
return
os
.
path
.
abspath
(
os
.
path
.
join
(
orig_dir
,
'
../..
'
,
new_locale
,
msgs_dir
,
orig_file
))
def
main
():
"""
Generate dummy strings for all source po files.
"""
LOCALE
=
CONFIGURATION
.
dummy_locale
SOURCE_MSGS_DIR
=
CONFIGURATION
.
source_messages_dir
print
"
Processing source language files into dummy strings:
"
for
source_file
in
CONFIGURATION
.
source_messages_dir
.
walkfiles
(
'
*.po
'
):
print
'
'
,
source_file
.
relpath
()
make_dummy
(
SOURCE_MSGS_DIR
.
joinpath
(
source_file
),
LOCALE
)
print
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
This diff is collapsed.
Click to expand it.
i18n/make_dummy.py
+
0
−
66
View file @
b06cf9cf
#!/usr/bin/env python
# Generate test translation files from human-readable po files.
#
# Dummy language is specified in configuration file (see config.py)
# two letter language codes reference:
# see http://www.loc.gov/standards/iso639-2/php/code_list.php
#
# Django will not localize in languages that django itself has not been
# localized for. So we are using a well-known language (default='eo').
# Django languages are listed in django.conf.global_settings.LANGUAGES
#
# po files can be generated with this:
# django-admin.py makemessages --all --extension html -l en
#
# Usage:
#
# $ ./make_dummy.py
#
# generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES,
# where $DUMMY_LOCALE is the dummy_locale value set in the i18n config
import
os
,
sys
import
polib
from
i18n.dummy
import
Dummy
from
i18n.config
import
CONFIGURATION
from
i18n.execute
import
create_dir_if_necessary
def
main
(
file
,
locale
):
"""
Takes a source po file, reads it, and writes out a new po file
in :param locale: containing a dummy translation.
"""
if
not
os
.
path
.
exists
(
file
):
raise
IOError
(
'
File does not exist: %s
'
%
file
)
pofile
=
polib
.
pofile
(
file
)
converter
=
Dummy
()
for
msg
in
pofile
:
converter
.
convert_msg
(
msg
)
# Apply declaration for English pluralization rules so that ngettext will
# do something reasonable.
pofile
.
metadata
[
'
Plural-Forms
'
]
=
'
nplurals=2; plural=(n != 1);
'
new_file
=
new_filename
(
file
,
locale
)
create_dir_if_necessary
(
new_file
)
pofile
.
save
(
new_file
)
def
new_filename
(
original_filename
,
new_locale
):
"""
Returns a filename derived from original_filename, using new_locale as the locale
"""
orig_dir
=
os
.
path
.
dirname
(
original_filename
)
msgs_dir
=
os
.
path
.
basename
(
orig_dir
)
orig_file
=
os
.
path
.
basename
(
original_filename
)
return
os
.
path
.
abspath
(
os
.
path
.
join
(
orig_dir
,
'
../..
'
,
new_locale
,
msgs_dir
,
orig_file
))
if
__name__
==
'
__main__
'
:
LOCALE
=
CONFIGURATION
.
dummy_locale
SOURCE_MSGS_DIR
=
CONFIGURATION
.
source_messages_dir
print
"
Processing source language files into dummy strings:
"
for
source_file
in
CONFIGURATION
.
source_messages_dir
.
walkfiles
(
'
*.po
'
):
print
'
'
,
source_file
.
relpath
()
main
(
SOURCE_MSGS_DIR
.
joinpath
(
source_file
),
LOCALE
)
print
This diff is collapsed.
Click to expand it.
i18n/tests/test_generate.py
+
9
−
2
View file @
b06cf9cf
...
...
@@ -3,13 +3,15 @@ import os
import
string
import
random
import
re
from
unittest
import
TestCase
from
unittest
import
TestCase
from
mock
import
patch
from
polib
import
pofile
from
pytz
import
UTC
from
i18n
import
extract
from
i18n
import
generate
from
i18n
import
dummy
from
i18n.config
import
CONFIGURATION
...
...
@@ -19,6 +21,11 @@ class TestGenerate(TestCase):
"""
generated_files
=
(
'
django-partial.po
'
,
'
djangojs-partial.po
'
,
'
mako.po
'
)
@classmethod
def
setUpClass
(
cls
):
extract
.
main
()
dummy
.
main
()
def
setUp
(
self
):
# Subtract 1 second to help comparisons with file-modify time succeed,
# since os.path.getmtime() is not millisecond-accurate
...
...
@@ -28,12 +35,12 @@ class TestGenerate(TestCase):
"""
Tests merge script on English source files.
"""
extract
.
main
()
filename
=
os
.
path
.
join
(
CONFIGURATION
.
source_messages_dir
,
random_name
())
generate
.
merge
(
CONFIGURATION
.
source_locale
,
target
=
filename
)
self
.
assertTrue
(
os
.
path
.
exists
(
filename
))
os
.
remove
(
filename
)
@patch.object
(
CONFIGURATION
,
'
locales
'
,
[
'
eo
'
])
def
test_main
(
self
):
"""
Runs generate.main() which should merge source files,
...
...
This diff is collapsed.
Click to expand it.
rakelib/i18n.rake
+
1
−
1
View file @
b06cf9cf
...
...
@@ -14,7 +14,7 @@ namespace :i18n do
desc
"Simulate international translation by generating dummy strings corresponding to source strings."
task
:dummy
=>
"i18n:extract"
do
sh
(
File
.
join
(
REPO_ROOT
,
"i18n"
,
"
make_
dummy.py"
))
sh
(
File
.
join
(
REPO_ROOT
,
"i18n"
,
"dummy.py"
))
end
namespace
:validate
do
...
...
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