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
d70eb3aa
Commit
d70eb3aa
authored
Jan 22, 2014
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test that validates that the .po and .mo files match for all active languages
parent
efa2cafa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
i18n/tests/test_compiled_messages.py
+59
-0
No files found.
i18n/tests/test_compiled_messages.py
0 → 100644
View file @
d70eb3aa
"""
Test that the compiled .mo files match the translations in the
uncompiled .po files.
This is required because we are checking in the .mo files into
the repo, but compiling them is a manual process. We want to make
sure that we find out if someone forgets the compilation step.
"""
import
ddt
import
polib
from
unittest
import
TestCase
from
i18n.config
import
CONFIGURATION
,
LOCALE_DIR
@ddt.ddt
class
TestCompiledMessages
(
TestCase
):
"""
Test that mo files match their source po files
"""
PO_FILES
=
[
'django.po'
,
'djangojs.po'
]
@ddt.data
(
*
CONFIGURATION
.
locales
)
def
test_translated_messages
(
self
,
locale
):
message_dir
=
LOCALE_DIR
/
locale
/
'LC_MESSAGES'
for
pofile_name
in
self
.
PO_FILES
:
pofile_path
=
message_dir
/
pofile_name
pofile
=
polib
.
pofile
(
pofile_path
)
mofile
=
polib
.
mofile
(
pofile_path
.
stripext
()
+
'.mo'
)
po_entries
=
{
entry
.
msgid
:
entry
for
entry
in
pofile
.
translated_entries
()}
mo_entries
=
{
entry
.
msgid
:
entry
for
entry
in
mofile
.
translated_entries
()}
# Check that there are no entries in po that aren't in mo, and vice-versa
self
.
assertEquals
(
po_entries
.
viewkeys
(),
mo_entries
.
viewkeys
())
for
entry_id
,
po_entry
in
po_entries
.
iteritems
():
mo_entry
=
mo_entries
[
entry_id
]
for
attr
in
(
'msgstr'
,
'msgid_plural'
,
'msgstr_plural'
,
'msgctxt'
,
'obsolete'
,
'encoding'
):
po_attr
=
getattr
(
po_entry
,
attr
)
mo_attr
=
getattr
(
mo_entry
,
attr
)
# The msgstr_plural in the mo_file is keyed on ints, but in the po_file it's
# keyed on strings. This normalizes them.
if
attr
==
'msgstr_plural'
:
po_attr
=
{
int
(
key
):
val
for
(
key
,
val
)
in
po_attr
.
items
()}
self
.
assertEquals
(
po_attr
,
mo_attr
,
"When comparing {} for entry {!r}, {!r} from the .po file doesn't match {!r} from the .mo file"
.
format
(
attr
,
entry_id
,
po_attr
,
mo_attr
,
)
)
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