Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
486582ec
Commit
486582ec
authored
Jul 02, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to specify base file for monolingual translations on import (issue #324)
parent
6e8619b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
4 deletions
+51
-4
docs/management.rst
docs/management.rst
+3
-0
trans/management/commands/import_project.py
trans/management/commands/import_project.py
+20
-4
trans/tests/commands.py
trans/tests/commands.py
+28
-0
No files found.
docs/management.rst
View file @
486582ec
...
...
@@ -87,6 +87,9 @@ To customise the subproject's name, use the `--name-template` option.
Its parameter is a python formatting string, which will expect the
match from `<filemask>`.
By format string passed by the `--base-file-template` option you can customize
base file for monolingual translations.
You can also specify file format to use (see :ref:`formats`) by the
`--file-format` parameter. The default is autodetection.
...
...
trans/management/commands/import_project.py
View file @
486582ec
...
...
@@ -45,6 +45,12 @@ class Command(BaseCommand):
help
=
'Python formatting string, transforming the filemask '
'match to a project name'
),
make_option
(
'--base-file-template'
,
default
=
'%s'
,
help
=
'Python formatting string, transforming the filemask '
'match to a monolingual base file name'
),
make_option
(
'--file-format'
,
default
=
'auto'
,
...
...
@@ -52,6 +58,14 @@ class Command(BaseCommand):
),
)
def
format_string
(
self
,
template
,
match
):
'''
Formats template string with match.
'''
if
'%s'
in
template
:
return
template
%
match
return
template
def
get_name
(
self
,
maskre
,
path
):
matches
=
maskre
.
match
(
path
)
return
matches
.
group
(
1
)
...
...
@@ -154,12 +168,12 @@ class Command(BaseCommand):
else
:
matches
,
sharedrepo
=
self
.
import_initial
(
project
,
repo
,
branch
,
filemask
,
options
[
'name_template'
],
options
[
'file_format'
]
options
[
'file_format'
]
,
options
[
'base_file_template'
]
)
# Create remaining subprojects sharing git repository
for
match
in
matches
:
name
=
options
[
'name_template'
]
%
match
name
=
self
.
format_string
(
options
[
'name_template'
],
match
)
slug
=
slugify
(
name
)
subprojects
=
SubProject
.
objects
.
filter
(
Q
(
name
=
name
)
|
Q
(
slug
=
slug
),
...
...
@@ -180,11 +194,12 @@ class Command(BaseCommand):
repo
=
sharedrepo
,
branch
=
branch
,
file_format
=
options
[
'file_format'
],
template
=
self
.
format_string
(
options
[
'base_file_template'
],
match
),
filemask
=
filemask
.
replace
(
'**'
,
match
)
)
def
import_initial
(
self
,
project
,
repo
,
branch
,
filemask
,
name_template
,
file_format
):
file_format
,
base_file_template
):
'''
Import the first repository of a project
'''
...
...
@@ -194,7 +209,7 @@ class Command(BaseCommand):
# Create first subproject (this one will get full git repo)
match
=
matches
.
pop
()
name
=
name_template
%
match
name
=
self
.
format_string
(
name_template
,
match
)
slug
=
slugify
(
name
)
if
SubProject
.
objects
.
filter
(
project
=
project
,
slug
=
slug
).
exists
():
...
...
@@ -221,6 +236,7 @@ class Command(BaseCommand):
repo
=
repo
,
branch
=
branch
,
file_format
=
file_format
,
template
=
self
.
format_string
(
base_file_template
,
match
),
filemask
=
filemask
.
replace
(
'**'
,
match
)
)
...
...
trans/tests/commands.py
View file @
486582ec
...
...
@@ -61,6 +61,34 @@ class ImportProjectTest(RepoTestCase):
# We should have loaded three subprojects
self
.
assertEqual
(
project
.
subproject_set
.
count
(),
4
)
def
test_import_aresource
(
self
):
project
=
self
.
create_project
()
call_command
(
'import_project'
,
'test'
,
self
.
repo_path
,
'master'
,
'**/values-*/strings.xml'
,
file_format
=
'aresource'
,
base_file_template
=
'android/values/strings.xml'
,
)
# We should have loaded one subproject
self
.
assertEqual
(
project
.
subproject_set
.
count
(),
1
)
def
test_import_aresource_format
(
self
):
project
=
self
.
create_project
()
call_command
(
'import_project'
,
'test'
,
self
.
repo_path
,
'master'
,
'**/values-*/strings.xml'
,
file_format
=
'aresource'
,
base_file_template
=
'%s/values/strings.xml'
,
)
# We should have loaded one subproject
self
.
assertEqual
(
project
.
subproject_set
.
count
(),
1
)
def
test_re_import
(
self
):
project
=
self
.
create_project
()
call_command
(
...
...
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