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
9ea21dd9
Commit
9ea21dd9
authored
Jan 21, 2014
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i18n: extract and generate properly handle segments
parent
05856903
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
16 deletions
+44
-16
conf/locale/config.yaml
+12
-0
i18n/config.py
+1
-2
i18n/execute.py
+1
-1
i18n/extract.py
+7
-1
i18n/generate.py
+19
-11
i18n/tests/test_generate.py
+4
-1
No files found.
conf/locale/config.yaml
View file @
9ea21dd9
...
...
@@ -59,3 +59,15 @@ segment:
mako.po
:
mako-studio.po
:
-
cms/*
# How should the generate step merge files?
generate_merge
:
django.po
:
-
django-partial.po
-
django-studio.po
-
mako.po
-
mako-studio.po
-
messages.po
djangojs.po
:
-
djangojs.po
-
djangojs-studio.po
i18n/config.py
View file @
9ea21dd9
...
...
@@ -14,8 +14,7 @@ LOCALE_DIR = BASE_DIR.joinpath('conf', 'locale')
class
Configuration
(
object
):
"""
# Reads localization configuration in json format
Reads localization configuration in json format.
"""
DEFAULTS
=
{
'generate_merge'
:
{},
...
...
i18n/execute.py
View file @
9ea21dd9
...
...
@@ -11,7 +11,7 @@ def execute(command, working_directory=BASE_DIR):
Output is ignored.
"""
LOG
.
info
(
command
)
subprocess
.
check_call
(
command
,
cwd
=
working_directory
,
stderr
=
s
y
s
.
STDOUT
,
shell
=
True
)
subprocess
.
check_call
(
command
,
cwd
=
working_directory
,
stderr
=
s
ubproces
s
.
STDOUT
,
shell
=
True
)
def
call
(
command
,
working_directory
=
BASE_DIR
):
...
...
i18n/extract.py
View file @
9ea21dd9
...
...
@@ -21,6 +21,7 @@ from polib import pofile
from
i18n.config
import
BASE_DIR
,
LOCALE_DIR
,
CONFIGURATION
from
i18n.execute
import
execute
,
create_dir_if_necessary
,
remove_file
from
i18n.segment
import
segment_pofiles
# BABEL_CONFIG contains declarations for Babel to extract strings from mako template files
...
...
@@ -44,7 +45,7 @@ def main():
# Prepare makemessages command.
makemessages
=
"django-admin.py makemessages -l en"
ignores
=
" "
.
join
(
"--ignore={}/*"
.
format
(
d
)
for
d
in
CONFIGURATION
.
ignore_dirs
)
ignores
=
" "
.
join
(
'--ignore="{}/*"'
.
format
(
d
)
for
d
in
CONFIGURATION
.
ignore_dirs
)
if
ignores
:
makemessages
+=
" "
+
ignores
...
...
@@ -67,6 +68,11 @@ def main():
source_msgs_dir
.
joinpath
(
'django-partial.po'
)
)
# Segment the generated files.
segmented_files
=
segment_pofiles
(
"en"
)
generated_files
.
extend
(
segmented_files
)
# Finish each file.
for
filename
in
generated_files
:
LOG
.
info
(
'Cleaning
%
s'
%
filename
)
po
=
pofile
(
source_msgs_dir
.
joinpath
(
filename
))
...
...
i18n/generate.py
View file @
9ea21dd9
...
...
@@ -22,10 +22,10 @@ from i18n.execute import execute
LOG
=
logging
.
getLogger
(
__name__
)
def
merge
(
locale
,
target
=
'django.po'
,
fail_if_missing
=
True
):
def
merge
(
locale
,
target
=
'django.po'
,
sources
=
(
'django-partial.po'
,),
fail_if_missing
=
True
):
"""
For the given locale, merge
django-partial.po, messages.po, mako.po -> django.po
target is the resulting filename
For the given locale, merge
the `sources` files to become the `target`
file. Note that the target file might also be one of the sources.
If fail_if_missing is true, and the files to be merged are missing,
throw an Exception, otherwise return silently.
...
...
@@ -34,18 +34,17 @@ def merge(locale, target='django.po', fail_if_missing=True):
just return silently.
"""
LOG
.
info
(
'Merging
locale={0}'
.
format
(
locale
))
LOG
.
info
(
'Merging
{target} for locale {locale}'
.
format
(
target
=
target
,
locale
=
locale
))
locale_directory
=
CONFIGURATION
.
get_messages_dir
(
locale
)
files_to_merge
=
(
'django-partial.po'
,
'messages.po'
,
'mako.po'
)
try
:
validate_files
(
locale_directory
,
files_to_merge
)
validate_files
(
locale_directory
,
sources
)
except
Exception
,
e
:
if
not
fail_if_missing
:
return
raise
e
# merged file is merged.po
merge_cmd
=
'msgcat -o merged.po '
+
' '
.
join
(
files_to_merge
)
merge_cmd
=
'msgcat -o merged.po '
+
' '
.
join
(
sources
)
execute
(
merge_cmd
,
working_directory
=
locale_directory
)
# clean up redunancies in the metadata
...
...
@@ -53,8 +52,16 @@ def merge(locale, target='django.po', fail_if_missing=True):
clean_metadata
(
merged_filename
)
# rename merged.po -> django.po (default)
django_filename
=
locale_directory
.
joinpath
(
target
)
os
.
rename
(
merged_filename
,
django_filename
)
# can't overwrite file on Windows
target_filename
=
locale_directory
.
joinpath
(
target
)
os
.
rename
(
merged_filename
,
target_filename
)
def
merge_files
(
locale
,
fail_if_missing
=
True
):
"""
Merge all the files in `locale`, as specified in config.yaml.
"""
for
target
,
sources
in
CONFIGURATION
.
generate_merge
.
items
():
merge
(
locale
,
target
,
sources
,
fail_if_missing
)
def
clean_metadata
(
file
):
...
...
@@ -85,9 +92,10 @@ def main():
logging
.
basicConfig
(
stream
=
sys
.
stdout
,
level
=
logging
.
INFO
)
for
locale
in
CONFIGURATION
.
locales
:
merge
(
locale
)
merge
_files
(
locale
)
# Dummy text is not required. Don't raise exception if files are missing.
merge
(
CONFIGURATION
.
dummy_locale
,
fail_if_missing
=
False
)
merge_files
(
CONFIGURATION
.
dummy_locale
,
fail_if_missing
=
False
)
compile_cmd
=
'django-admin.py compilemessages'
execute
(
compile_cmd
,
working_directory
=
BASE_DIR
)
...
...
i18n/tests/test_generate.py
View file @
9ea21dd9
...
...
@@ -49,7 +49,10 @@ class TestGenerate(TestCase):
self
.
assertTrue
(
exists
,
msg
=
'Missing file in locale
%
s:
%
s'
%
(
locale
,
mofile
))
self
.
assertTrue
(
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
path
),
UTC
)
>=
self
.
start_time
,
msg
=
'File not recently modified:
%
s'
%
path
)
self
.
assert_merge_headers
(
locale
)
# Segmenting means that the merge headers don't work they way they
# used to, so don't make this check for now. I'm not sure if we'll
# get the merge header back eventually, or delete this code eventually.
# self.assert_merge_headers(locale)
def
assert_merge_headers
(
self
,
locale
):
"""
...
...
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