Skip to content

Conversation

@amCap1712
Copy link
Contributor

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.

Fixes #14039

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.
@amCap1712 amCap1712 requested a review from nijel as a code owner December 12, 2025 21:26
@amCap1712
Copy link
Contributor Author

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?

Copy link
Member

@nijel nijel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nijel
Copy link
Member

nijel commented Dec 13, 2025

Oh, and I don't have preference out of these two stay, it should not flip them if one is already present.

@amCap1712 amCap1712 requested a review from nijel December 16, 2025 07:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_translated flag 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

Comment on lines +313 to +314
def set_automatically_translated(self, value: bool) -> None:
return
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@nijel
Copy link
Member

nijel commented Dec 17, 2025

@amCap1712 Do you think this is good to include in 5.15.1?

@amCap1712
Copy link
Contributor Author

@nijel Yes, I did some manual tests and added some to automated tests as well and am happy with the changes.

@nijel
Copy link
Member

nijel commented Dec 17, 2025

Some tests are failing, can you check it?

@amCap1712
Copy link
Contributor Author

on it.

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 97.56098% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.70%. Comparing base (1bc3859) to head (4f6d70f).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
weblate/formats/ttkit.py 95.00% 0 Missing and 1 partial ⚠️
weblate/trans/models/pending.py 66.66% 0 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (97.56%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nijel nijel added this to the 5.15.1 milestone Dec 17, 2025
@nijel nijel merged commit 0f4c557 into WeblateOrg:main Dec 17, 2025
53 of 54 checks passed
@nijel
Copy link
Member

nijel commented Dec 17, 2025

Merged, thanks for your contribution!

@amCap1712 amCap1712 deleted the autotranslate-xliff branch December 17, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leverage state-qualifier from XLIFF

2 participants