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
9011e6e1
Commit
9011e6e1
authored
Jan 03, 2014
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix plural handling, put teeth in msgfmt -c test.
parent
d8df97aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
23 deletions
+22
-23
i18n/dummy.py
+4
-16
i18n/generate.py
+5
-2
i18n/make_dummy.py
+7
-1
i18n/tests/test_validate.py
+6
-4
No files found.
i18n/dummy.py
View file @
9011e6e1
...
...
@@ -99,20 +99,6 @@ class Dummy(Converter):
"""replaces the final char of string with #"""
return
string
[:
-
1
]
+
'#'
def
init_msgs
(
self
,
msgs
):
"""
Make sure the first msg in msgs has a plural property.
msgs is list of instances of polib.POEntry
"""
if
not
msgs
:
return
headers
=
msgs
[
0
]
.
get_property
(
'msgstr'
)
has_plural
=
any
(
header
.
startswith
(
'Plural-Forms:'
)
for
header
in
headers
)
if
not
has_plural
:
# Apply declaration for English pluralization rules
plural
=
"Plural-Forms: nplurals=2; plural=(n != 1);
\\
n"
headers
.
append
(
plural
)
def
convert_msg
(
self
,
msg
):
"""
Takes one POEntry object and converts it (adds a dummy translation to it)
...
...
@@ -128,8 +114,10 @@ class Dummy(Converter):
# translate singular and plural
foreign_single
=
self
.
convert
(
source
)
foreign_plural
=
self
.
convert
(
plural
)
plural
=
{
'0'
:
self
.
final_newline
(
source
,
foreign_single
),
'1'
:
self
.
final_newline
(
plural
,
foreign_plural
)}
plural
=
{
'0'
:
self
.
final_newline
(
source
,
foreign_single
),
'1'
:
self
.
final_newline
(
plural
,
foreign_plural
),
}
msg
.
msgstr_plural
=
plural
else
:
foreign
=
self
.
convert
(
source
)
...
...
i18n/generate.py
View file @
9011e6e1
...
...
@@ -60,9 +60,12 @@ def merge(locale, target='django.po', fail_if_missing=True):
def
clean_metadata
(
file
):
"""
Clean up redundancies in the metadata caused by merging.
This reads in a PO file and simply saves it back out again.
"""
pofile
(
file
)
.
save
()
# Reading in the .po file and saving it again fixes redundancies.
pomsgs
=
pofile
(
file
)
# The msgcat tool marks the metadata as fuzzy, but it's ok as it is.
pomsgs
.
metadata_is_fuzzy
=
False
pomsgs
.
save
()
def
validate_files
(
dir
,
files_to_merge
):
...
...
i18n/make_dummy.py
View file @
9011e6e1
...
...
@@ -38,9 +38,15 @@ def main(file, locale):
raise
IOError
(
'File does not exist:
%
s'
%
file
)
pofile
=
polib
.
pofile
(
file
)
converter
=
Dummy
()
converter
.
init_msgs
(
pofile
.
translated_entries
())
for
msg
in
pofile
:
converter
.
convert_msg
(
msg
)
# If any message has a plural, then the file needs plural information.
# Apply declaration for English pluralization rules so that ngettext will
# do something reasonable.
if
any
(
m
.
msgid_plural
for
m
in
pofile
):
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
)
...
...
i18n/tests/test_validate.py
View file @
9011e6e1
...
...
@@ -12,9 +12,9 @@ def test_po_files(root=LOCALE_DIR):
log
=
logging
.
getLogger
(
__name__
)
logging
.
basicConfig
(
stream
=
sys
.
stdout
,
level
=
logging
.
INFO
)
for
(
dirpath
,
dirnames
,
filenames
)
in
os
.
walk
(
root
):
for
dirpath
,
__
,
filenames
in
os
.
walk
(
root
):
for
name
in
filenames
:
(
base
,
ext
)
=
os
.
path
.
splitext
(
name
)
__
,
ext
=
os
.
path
.
splitext
(
name
)
if
ext
.
lower
()
==
'.po'
:
yield
validate_po_file
,
os
.
path
.
join
(
dirpath
,
name
),
log
...
...
@@ -26,6 +26,8 @@ def validate_po_file(filename, log):
"""
# Use relative paths to make output less noisy.
rfile
=
os
.
path
.
relpath
(
filename
,
LOCALE_DIR
)
(
out
,
err
)
=
call
([
'msgfmt'
,
'-c'
,
rfile
],
working_directory
=
LOCALE_DIR
)
out
,
err
=
call
([
'msgfmt'
,
'-c'
,
rfile
],
working_directory
=
LOCALE_DIR
)
if
err
!=
''
:
log
.
warn
(
'
\n
'
+
err
)
log
.
info
(
'
\n
'
+
out
)
log
.
warn
(
'
\n
'
+
err
)
assert
not
err
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