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): ...@@ -50,28 +50,31 @@ def auto_translate(user, translation, source, inconsistent, overwrite):
translation=translation translation=translation
) )
# Filter by strings
units = units.filter(
source__in=sources.values('source')
)
translation.commit_pending(None) translation.commit_pending(None)
for unit in units.iterator(): for unit in units.iterator():
update = sources.filter(source=unit.source) # Get first matching entry
if update.exists(): update = sources.filter(source=unit.source)[0]
# Get first entry # No save if translation is same
update = update[0] if unit.fuzzy == update.fuzzy and unit.target == update.target:
# No save if translation is same continue
if unit.fuzzy == update.fuzzy and unit.target == update.target: # Copy translation
continue unit.fuzzy = update.fuzzy
# Copy translation unit.target = update.target
unit.fuzzy = update.fuzzy # Create signle change object for whole merge
unit.target = update.target change = Change.objects.create(
# Create signle change object for whole merge action=Change.ACTION_AUTO,
change = Change.objects.create( unit=unit,
action=Change.ACTION_AUTO, user=user,
unit=unit, author=user
user=user, )
author=user # Save unit to backend
) unit.save_backend(None, False, False, user=user)
# Save unit to backend updated += 1
unit.save_backend(None, False, False, user=user)
updated += 1
return updated 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