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
1ff72bf6
Commit
1ff72bf6
authored
Aug 14, 2014
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly implement file upload for template based translations
Fixes #504 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
5a0f5c46
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
4 deletions
+66
-4
weblate/trans/models/translation.py
weblate/trans/models/translation.py
+40
-4
weblate/trans/tests/data/strings-cs.xml
weblate/trans/tests/data/strings-cs.xml
+5
-0
weblate/trans/tests/test_files.py
weblate/trans/tests/test_files.py
+21
-0
No files found.
weblate/trans/models/translation.py
View file @
1ff72bf6
...
...
@@ -41,7 +41,7 @@ from weblate.trans.formats import AutoFormat
from
weblate.trans.checks
import
CHECKS
from
weblate.trans.models.project
import
Project
from
weblate.trans.util
import
(
get_site_url
,
sleep_while_git_locked
,
translation_percent
get_site_url
,
sleep_while_git_locked
,
translation_percent
,
split_plural
,
)
from
weblate.accounts.avatar
import
get_user_display
from
weblate.trans.mixins
import
URLMixin
,
PercentMixin
...
...
@@ -1119,6 +1119,31 @@ class Translation(models.Model, URLMixin, PercentMixin):
return
result
def
merge_translations
(
self
,
request
,
author
,
store2
,
overwrite
,
add_fuzzy
):
"""
Merges translation unit wise, needed for template based translations to
add new strings.
"""
for
unit2
in
store2
.
all_units
():
# No translated -> skip
if
not
unit2
.
is_translated
()
or
unit2
.
unit
.
isheader
():
continue
try
:
unit
=
self
.
unit_set
.
get
(
source
=
unit2
.
get_source
(),
context
=
unit2
.
get_context
(),
)
except
Unit
.
DoesNotExist
:
continue
unit
.
translate
(
request
,
split_plural
(
unit2
.
get_target
()),
add_fuzzy
or
unit2
.
is_fuzzy
()
)
def
merge_store
(
self
,
request
,
author
,
store2
,
overwrite
,
merge_header
,
add_fuzzy
):
'''
...
...
@@ -1241,15 +1266,26 @@ class Translation(models.Model, URLMixin, PercentMixin):
if
method
in
(
''
,
'fuzzy'
):
# Do actual merge
for
translation
in
translations
:
ret
|=
translation
.
merge_store
(
if
self
.
subproject
.
has_template
():
# Merge on units level
self
.
merge_translations
(
request
,
author
,
store
,
overwrite
,
merge_header
,
(
method
==
'fuzzy'
)
)
else
:
# Merge on file level
for
translation
in
translations
:
ret
|=
translation
.
merge_store
(
request
,
author
,
store
,
overwrite
,
merge_header
,
(
method
==
'fuzzy'
)
)
else
:
# Add as sugestions
ret
=
self
.
merge_suggestions
(
request
,
store
)
...
...
weblate/trans/tests/data/strings-cs.xml
0 → 100644
View file @
1ff72bf6
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string
name=
"hello"
>
Nazdar světe!\n
</string>
<string
name=
"orangutan"
>
Orangutan má %d banány.\n
</string>
</resources>
weblate/trans/tests/test_files.py
View file @
1ff72bf6
...
...
@@ -28,6 +28,7 @@ from weblate.trans.tests.test_util import get_test_file
TEST_PO
=
get_test_file
(
'cs.po'
)
TEST_MO
=
get_test_file
(
'cs.mo'
)
TEST_ANDROID
=
get_test_file
(
'strings-cs.xml'
)
TRANSLATION_OURS
=
u'Nazdar světe!
\
n
'
TRANSLATION_PO
=
u'Ahoj světe!
\
n
'
...
...
@@ -183,6 +184,26 @@ class ImportMoPoTest(ImportTest):
return
self
.
create_po
()
class
AndroidImportTest
(
ViewTestCase
):
def
create_subproject
(
self
):
return
self
.
create_android
()
def
test_import
(
self
):
with
open
(
TEST_ANDROID
)
as
handle
:
self
.
client
.
post
(
reverse
(
'upload_translation'
,
kwargs
=
self
.
kw_translation
),
{
'file'
:
handle
}
)
# Verify stats
translation
=
self
.
get_translation
()
self
.
assertEqual
(
translation
.
translated
,
2
)
self
.
assertEqual
(
translation
.
fuzzy
,
0
)
self
.
assertEqual
(
translation
.
total
,
4
)
class
ExportTest
(
ViewTestCase
):
'''
Testing of file export.
...
...
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