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
63de4112
Commit
63de4112
authored
Jan 21, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added management command for auto translation
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
5d5737de
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
205 additions
and
4 deletions
+205
-4
docs/admin/management.rst
docs/admin/management.rst
+27
-0
docs/changes.rst
docs/changes.rst
+1
-0
docs/user/translating.rst
docs/user/translating.rst
+2
-0
weblate/trans/management/commands/auto_translate.py
weblate/trans/management/commands/auto_translate.py
+111
-0
weblate/trans/tests/test_autotranslate.py
weblate/trans/tests/test_autotranslate.py
+64
-4
No files found.
docs/admin/management.rst
View file @
63de4112
...
...
@@ -31,6 +31,33 @@ Example:
./manage.py --author michal@cihar.com add_suggestions weblate master cs /tmp/suggestions-cs.po
auto_translate <project> <component> <language>
-----------------------------------------------
.. django-admin:: auto_translate
.. versionadded:: 2.5
Performs automatic translation based on other component translations.
By default it uses all other components from current project, but you can
specify other source component by ``--source`` parameter.
All changes are by default authored by anonymous user, you can specify another
username by ``--user``.
The ``--overwrite`` and ``--inconsistent`` parameters control which strings
will be updated.
Example:
.. code-block:: sh
./manage.py --user nijel --inconsistent --source phpmyadmin/master phpmyadmin 4-5 cs
.. seealso:: :ref:`auto-translation`
changesite
----------
...
...
docs/changes.rst
View file @
63de4112
...
...
@@ -27,6 +27,7 @@ Released on ? 2015.
* Improved targeting for whiteboard messages.
* Support for automatic translation across projects.
* Optimized fulltext search index.
* Added management command for auto translation.
weblate 2.4
-----------
...
...
docs/user/translating.rst
View file @
63de4112
...
...
@@ -166,6 +166,8 @@ All machine translations are available on single tab on translation page.
.. seealso:: :ref:`machine-translation-setup`
.. _auto-translation:
Automatic translation
---------------------
...
...
weblate/trans/management/commands/auto_translate.py
0 → 100644
View file @
63de4112
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2016 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.contrib.auth.models
import
User
from
django.http.request
import
HttpRequest
from
weblate.trans.models
import
Translation
,
SubProject
from
weblate.accounts.models
import
get_author_name
from
weblate.trans.autotranslate
import
auto_translate
class
Command
(
BaseCommand
):
"""
Command for mass automatic translation.
"""
help
=
'performs automatic translation based on other components'
args
=
'<project> <component> <language>'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--user'
,
default
=
'anonymous'
,
help
=
(
'User performing the change'
,
)
),
make_option
(
'--source'
,
default
=
''
,
help
=
(
'Source component <project/component>'
)
),
make_option
(
'--overwrite'
,
default
=
False
,
action
=
'store_true'
,
help
=
(
'Overwrite existing translations in target component'
)
),
make_option
(
'--inconsistent'
,
default
=
False
,
action
=
'store_true'
,
help
=
(
'Process only inconsistent translations'
)
),
)
def
handle
(
self
,
*
args
,
**
options
):
# Check params
if
len
(
args
)
!=
3
:
raise
CommandError
(
'Invalid number of parameters!'
)
# Get translation object
try
:
translation
=
Translation
.
objects
.
get
(
subproject__project__slug
=
args
[
0
],
subproject__slug
=
args
[
1
],
language__code
=
args
[
2
],
)
except
Translation
.
DoesNotExist
:
raise
CommandError
(
'No matching translation project found!'
)
# Get user
try
:
user
=
User
.
objects
.
get
(
username
=
options
[
'user'
])
except
User
.
DoesNotExist
:
raise
CommandError
(
'User does not exist!'
)
if
options
[
'source'
]:
parts
=
options
[
'source'
].
split
(
'/'
)
if
len
(
parts
)
!=
2
:
raise
CommandError
(
'Invalid source component specified!'
)
try
:
subproject
=
SubProject
.
objects
.
get
(
project__slug
=
parts
[
0
],
slug
=
parts
[
1
],
)
except
SubProject
.
DoesNotExist
:
raise
CommandError
(
'No matching source component found!'
)
source
=
subproject
.
id
else
:
source
=
''
result
=
auto_translate
(
user
,
translation
,
source
,
options
[
'inconsistent'
],
options
[
'overwrite'
]
)
self
.
stdout
.
write
(
'Updated {0} units'
.
format
(
result
))
weblate/trans/tests/test_autotranslate.py
View file @
63de4112
...
...
@@ -23,6 +23,8 @@ Tests for automatic translation
"""
from
django.core.urlresolvers
import
reverse
from
django.core.management
import
call_command
from
django.core.management.base
import
CommandError
from
weblate.trans.models
import
SubProject
from
weblate.trans.tests.test_views
import
ViewTestCase
...
...
@@ -58,14 +60,17 @@ class AutoTranslationTest(ViewTestCase):
)
self
.
assertRedirects
(
response
,
self
.
translation_url
)
def
test_different
(
self
):
'''
Tests for automatic translation with different content.
'''
def
make_different
(
self
):
self
.
edit_unit
(
'Hello, world!
\
n
'
,
'Nazdar svete!
\
n
'
)
def
test_different
(
self
):
'''
Tests for automatic translation with different content.
'''
self
.
make_different
()
params
=
{
'project'
:
'test'
,
'lang'
:
'cs'
,
'subproject'
:
'test-2'
}
url
=
reverse
(
'auto_translation'
,
kwargs
=
params
)
response
=
self
.
client
.
post
(
url
,
follow
=
True
)
...
...
@@ -78,3 +83,58 @@ class AutoTranslationTest(ViewTestCase):
# Check we've translated something
translation
=
self
.
subproject2
.
translation_set
.
get
(
language_code
=
'cs'
)
self
.
assertEqual
(
translation
.
translated
,
1
)
def
test_command
(
self
):
call_command
(
'auto_translate'
,
'test'
,
'test'
,
'cs'
,
)
def
test_command_different
(
self
):
self
.
make_different
()
call_command
(
'auto_translate'
,
'test'
,
'test-2'
,
'cs'
,
source
=
'test/test'
,
)
def
test_command_errors
(
self
):
self
.
assertRaises
(
CommandError
,
call_command
,
'auto_translate'
,
'test'
,
'test'
,
'cs'
,
user
=
'invalid'
,
)
self
.
assertRaises
(
CommandError
,
call_command
,
'auto_translate'
,
'test'
,
'test'
,
'cs'
,
source
=
'invalid'
,
)
self
.
assertRaises
(
CommandError
,
call_command
,
'auto_translate'
,
'test'
,
'test'
,
'cs'
,
source
=
'test/invalid'
,
)
self
.
assertRaises
(
CommandError
,
call_command
,
'auto_translate'
,
'test'
,
'test'
,
'xxx'
,
)
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