Commit 7080d388 authored by Michal Čihař's avatar Michal Čihař

Do auto translation string matching at database level

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c65e3d58
......@@ -50,28 +50,31 @@ def auto_translate(user, translation, source, inconsistent, overwrite):
translation=translation
)
# Filter by strings
units = units.filter(
source__in=sources.values('source')
)
translation.commit_pending(None)
for unit in units.iterator():
update = sources.filter(source=unit.source)
if update.exists():
# Get first entry
update = update[0]
# No save if translation is same
if unit.fuzzy == update.fuzzy and unit.target == update.target:
continue
# Copy translation
unit.fuzzy = update.fuzzy
unit.target = update.target
# Create signle change object for whole merge
change = Change.objects.create(
action=Change.ACTION_AUTO,
unit=unit,
user=user,
author=user
)
# Save unit to backend
unit.save_backend(None, False, False, user=user)
updated += 1
# Get first matching entry
update = sources.filter(source=unit.source)[0]
# No save if translation is same
if unit.fuzzy == update.fuzzy and unit.target == update.target:
continue
# Copy translation
unit.fuzzy = update.fuzzy
unit.target = update.target
# Create signle change object for whole merge
change = Change.objects.create(
action=Change.ACTION_AUTO,
unit=unit,
user=user,
author=user
)
# Save unit to backend
unit.save_backend(None, False, False, user=user)
updated += 1
return updated
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment