Skip to content

Align built-in pretranslation with API path - #4606

Open
baha-bouali wants to merge 2 commits into
mozilla:mainfrom
baha-bouali:align-built-in-with-API-pretranslations
Open

baha-bouali wants to merge 2 commits into
mozilla:mainfrom
baha-bouali:align-built-in-with-API-pretranslations

Conversation

@baha-bouali

Copy link
Copy Markdown
Contributor

Fixes #4526

What changed

Following the points agreed in the issue, the built-in pretranslation now follows the
same rules as the pretranslation upload API.

Behavior

  • Strings with unreviewed suggestions are pretranslated. A suggestion matching the
    pretranslation becomes the pretranslation and keeps its author; other suggestions are
    kept, only deactivated.

  • Fuzzy translations and older, different pretranslations are rejected and replaced; a
    matching one is converted instead.

  • Strings with an approved translation are skipped, before calling machine translation.

  • A pretranslation that still fails checks after the retry with preserved placeables is
    not stored.

  • Strings whose pretranslation was rejected are still never pretranslated again, and
    Translate Toolkit checks stay disabled.

    Structure

  • decide_pretranslation() (in sync/upload.py) holds the decision both paths share.

  • reject_translations() is a shared helper for rejecting and logging.

  • The built-in path has its own write, write_pretranslations(), since it differs from
    the API: bot authors, per-resource stats and latest translation, no check results to
    store, and dropping strings instead of raising.

  • Writes happen in order: reject → deactivate → update → create, so a string never has
    two active translations.

    Choices

Those still need your confirmation:

  • Rejections are recorded as the Sync system user. Insights ignores it, so these
    automatic rejections don't count against pretranslation quality.
  • The built-in write also takes lock_import_target(), so it waits for an upload of the
    same strings instead of colliding with it.
  • bulk_run_checks() is gone: everything stored has passed all checks, and the stale
    warnings and errors of converted suggestions are deleted.
  • The latest translation of each resource is the newest one written, since a converted
    suggestion can be months old.

Docs

With these changes, two docs no longer described the behavior correctly, so I
updated docs/dev/api.md and docs/admin/managing-pretranslation.md to match.

Tests

This is a draft, and new tests will follow.

@baha-bouali baha-bouali changed the title align-both-paths-before-adding-tests Align built-in pretranslation with API path Oct 14, 2026
@baha-bouali

baha-bouali commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

A small note aside

This one took me roughly three weeks. Most of that time went into reading the code and studying the possible solutions. That was intentional: I wanted a deeper understanding of how pretranslation, uploads and the translation data fit together, and I got it.

@mathjazz

Copy link
Copy Markdown
Collaborator

Thanks @baha-bouali — the structure matches what we agreed, and the converted match correctly keeps its original author.

I'll wait for you to address the outcomes of our discussion before digging deeper.

This branch has not been deployed

No deployments
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.

Align built-in pretranslation with the pretranslation upload API

2 participants