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
5d8dc390
Commit
5d8dc390
authored
Mar 12, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use wrapper unit class instead of directly using ttkit
parent
3e6e69f7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
73 deletions
+65
-73
trans/formats.py
trans/formats.py
+39
-1
trans/models/translation.py
trans/models/translation.py
+10
-29
trans/models/unit.py
trans/models/unit.py
+16
-43
No files found.
trans/formats.py
View file @
5d8dc390
...
...
@@ -53,7 +53,7 @@ class FileUnit(object):
'''
self
.
unit
=
unit
self
.
template
=
template
if
unit
is
None
:
if
template
is
not
None
:
self
.
mainunit
=
template
else
:
self
.
mainunit
=
unit
...
...
@@ -165,6 +165,14 @@ class FileUnit(object):
else
:
return
self
.
unit
.
istranslated
()
def
is_fuzzy
(
self
):
'''
Checks whether unit is translated.
'''
if
self
.
unit
is
None
:
return
False
return
self
.
unit
.
isfuzzy
()
def
is_translatable
(
self
):
'''
Checks whether unit is translatable.
...
...
@@ -315,6 +323,36 @@ class FileFormat(object):
'''
self
.
store
.
save
()
def
translatable_units
(
self
):
'''
Generator of translatable units.
'''
if
not
self
.
has_template
:
for
tt_unit
in
self
.
store
.
units
:
# Create wrapper object
unit
=
FileUnit
(
tt_unit
)
# We care only about translatable strings
if
not
unit
.
is_translatable
():
continue
yield
unit
else
:
for
template_unit
in
self
.
template_store
.
units
:
# Create wrapper object (not translated)
unit
=
FileUnit
(
None
,
template_unit
)
# We care only about translatable strings
if
not
unit
.
is_translatable
():
continue
# Get translated unit (if it exists)
unit
.
unit
=
self
.
store
.
findid
(
template_unit
.
getid
())
yield
unit
@
property
def
mimetype
(
self
):
'''
...
...
trans/models/translation.py
View file @
5d8dc390
...
...
@@ -443,11 +443,7 @@ class Translation(models.Model):
# Position of current unit
pos
=
1
if
not
self
.
store
.
has_template
:
for
unit
in
self
.
store
.
store
.
units
:
# We care only about translatable strings
if
not
is_translatable
(
unit
):
continue
for
unit
in
self
.
store
.
translatable_units
():
newunit
,
is_new
=
Unit
.
objects
.
update_from_unit
(
self
,
unit
,
pos
)
...
...
@@ -457,21 +453,6 @@ class Translation(models.Model):
oldunits
.
remove
(
newunit
.
id
)
except
:
pass
else
:
for
template_unit
in
self
.
store
.
template_store
.
units
:
# We care only about translatable strings
if
not
is_translatable
(
template_unit
):
continue
unit
=
self
.
store
.
store
.
findid
(
template_unit
.
getid
())
newunit
,
is_new
=
Unit
.
objects
.
update_from_unit
(
self
,
unit
,
pos
,
template
=
template_unit
)
was_new
=
was_new
or
(
is_new
and
not
newunit
.
translated
)
pos
+=
1
try
:
oldunits
.
remove
(
newunit
.
id
)
except
:
pass
# Delete not used units
units_to_delete
=
Unit
.
objects
.
filter
(
...
...
trans/models/unit.py
View file @
5d8dc390
...
...
@@ -37,24 +37,21 @@ from trans.data import IGNORE_SIMILAR
from
trans.filelock
import
FileLockException
from
trans.util
import
(
is_plural
,
split_plural
,
join_plural
,
msg_checksum
,
get_source
,
get_target
,
get_context
,
is_translated
,
msg_checksum
,
is_translated
,
)
logger
=
logging
.
getLogger
(
'weblate'
)
class
UnitManager
(
models
.
Manager
):
def
update_from_unit
(
self
,
translation
,
unit
,
pos
,
template
=
None
):
def
update_from_unit
(
self
,
translation
,
unit
,
pos
):
'''
Process translation toolkit unit and stores/updates database entry.
'''
if
template
is
None
:
src
=
get_source
(
unit
)
ctx
=
get_context
(
unit
)
else
:
src
=
get_target
(
template
)
ctx
=
get_context
(
template
)
src
=
unit
.
get_source
()
ctx
=
unit
.
get_context
()
# TODO: move to unit
checksum
=
msg_checksum
(
src
,
ctx
)
# Try getting existing unit
...
...
@@ -85,7 +82,7 @@ class UnitManager(models.Manager):
created
=
True
# Update all details
dbunit
.
update_from_unit
(
unit
,
pos
,
created
,
template
)
dbunit
.
update_from_unit
(
unit
,
pos
,
created
)
# Return result
return
dbunit
,
created
...
...
@@ -418,47 +415,23 @@ class Unit(models.Model):
self
.
translation
.
get_translate_url
(),
self
.
checksum
)
def
update_from_unit
(
self
,
unit
,
pos
,
created
,
template
=
None
):
def
update_from_unit
(
self
,
unit
,
pos
,
created
):
'''
Updates Unit from ttkit unit.
'''
# Template is optional
if
template
is
None
:
template
=
unit
# Merge locations
location
=
', '
.
join
(
template
.
getlocations
())
# Merge flags
if
unit
is
not
None
and
hasattr
(
unit
,
'typecomments'
):
flags
=
', '
.
join
(
unit
.
typecomments
)
elif
template
is
not
None
and
hasattr
(
template
,
'typecomments'
):
flags
=
', '
.
join
(
template
.
typecomments
)
else
:
flags
=
''
# Get target
target
=
get_target
(
unit
)
# Get data from unit
if
unit
is
None
:
fuzzy
=
False
translated
=
False
if
template
is
None
:
comment
=
''
else
:
comment
=
template
.
getnotes
()
else
:
fuzzy
=
unit
.
isfuzzy
()
translated
=
is_translated
(
unit
)
comment
=
unit
.
getnotes
()
if
template
is
not
None
:
# Avoid duplication in case template has same comments
template_comment
=
template
.
getnotes
()
if
template_comment
!=
comment
:
comment
=
template_comment
+
' '
+
comment
# Get unit attributes
location
=
unit
.
get_locations
()
flags
=
unit
.
get_flags
()
target
=
unit
.
get_target
()
comment
=
unit
.
get_comments
()
fuzzy
=
unit
.
is_fuzzy
()
translated
=
unit
.
is_translated
()
# Update checks on fuzzy update or on content change
same_content
=
(
target
==
self
.
target
)
same_fuzzy
=
(
fuzzy
==
self
.
fuzzy
)
# TODO: move to unit class
if
fuzzy
and
hasattr
(
unit
,
'prev_source'
):
if
hasattr
(
unit
.
prev_source
,
'strings'
):
previous_source
=
join_plural
(
unit
.
prev_source
.
strings
)
...
...
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