feat: detect automatically translated units from XLIFF state-qualifier#17294
feat: detect automatically translated units from XLIFF state-qualifier#17294nijel merged 6 commits intoWeblateOrg:mainfrom
Conversation
Add support for detecting machine-translated units in XLIFF files based on the state-qualifier attribute. Units with "leveraged-mt" or "mt-suggestion" state qualifiers are now marked as automatically translated when imported. To implement this, a `is_automatically_translated` method has been added to the base TranslationUnit class and it is used to set the `automatically_translated` flag in database during unit import.
|
If a unit is marked automatically translated in Weblate, should we write it to the xliff file as well? If yes, which of the two state qualifiers should we choose? |
nijel
left a comment
There was a problem hiding this comment.
I think we need something similar to fuzzy and approved states. If the file format supports it, store it there, if not preserve the flag if nothing changes in the file.
|
Oh, and I don't have preference out of these two stay, it should not flip them if one is already present. |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR adds automatic detection of machine-translated units in XLIFF files based on the state-qualifier attribute. Units with "leveraged-mt" or "mt-suggestion" state qualifiers are now marked as automatically translated during import and sync operations.
Key changes:
- Added
is_automatically_translated()method to the base TranslationUnit class with XLIFF-specific implementation - Modified unit import/update logic to preserve and sync the
automatically_translatedflag between file and database - Extended PendingUnitChange model to track automatically translated state during commits
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| weblate/formats/base.py | Added base is_automatically_translated() and set_automatically_translated() methods to TranslationUnit class |
| weblate/formats/ttkit.py | Implemented XLIFF-specific detection and setting of automatic translation via state-qualifier attribute |
| weblate/trans/models/unit.py | Updated unit import logic to read and preserve automatically_translated flag from files |
| weblate/trans/models/translation.py | Modified update_units to sync automatically_translated state to files during commits |
| weblate/trans/models/pending.py | Extended PendingUnitChange model to track automatically_translated field |
| weblate/trans/migrations/0061_pendingunitchange_automatically_translated.py | Database migration to add automatically_translated field |
| weblate/trans/tests/test_models.py | Added comprehensive tests for XLIFF state-qualifier import and sync behavior |
| weblate/trans/tests/utils.py | Added helper method to create test XLIFF component |
| weblate/trans/tests/data/cs-auto.xliff | Test fixture with various state-qualifier configurations |
| weblate/formats/tests/test_formats.py | Added unit tests for state-qualifier detection |
weblate/trans/migrations/0061_pendingunitchange_automatically_translated.py
Outdated
Show resolved
Hide resolved
| def set_automatically_translated(self, value: bool) -> None: | ||
| return |
There was a problem hiding this comment.
The method body contains only a return statement without any implementation. Consider using 'pass' instead to make it clear this is an intentionally empty method, or add a docstring explaining why subclasses may override this.
|
@amCap1712 Do you think this is good to include in 5.15.1? |
|
@nijel Yes, I did some manual tests and added some to automated tests as well and am happy with the changes. |
|
Some tests are failing, can you check it? |
|
on it. |
Codecov Report❌ Patch coverage is
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Merged, thanks for your contribution! |
Add support for detecting machine-translated units in XLIFF files based on the state-qualifier attribute. Units with "leveraged-mt" or "mt-suggestion" state qualifiers are now marked as automatically translated when imported. To implement this, a
is_automatically_translatedmethod has been added to the base TranslationUnit class and it is used to set theautomatically_translatedflag in database during unit import.Fixes #14039