Skip to content

Batch actions: Add the ability to pretranslate strings - #4455

Open
MundiaNderi wants to merge 5 commits into
mozilla:mainfrom
MundiaNderi:pretranslate-2790
Open

MundiaNderi wants to merge 5 commits into
mozilla:mainfrom
MundiaNderi:pretranslate-2790

Conversation

@MundiaNderi

@MundiaNderi MundiaNderi commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2790

This is a draft pr because I want to context switch

Allows contributors to manually batch pretranslate strings for locales supported by translation engines.

@MundiaNderi MundiaNderi changed the title Fixes #2790 Batch actions: Add the ability to pretranslate strings Aug 27, 2026
@codecov-commenter

codecov-commenter commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.80000% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.50%. Comparing base (4e07692) to head (b0bc75a).
⚠️ Report is 3 commits behind head on main.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flodolo

flodolo commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

I haven't looked at the code, but

Teams might want to benefit from pretranslation capabilities on projects for which pretranslation is not enabled (by the admins).

This should not be available to contributors. I would go as far as to limit this to members of the pretranslator group.

@MundiaNderi MundiaNderi self-assigned this Aug 27, 2026
@mathjazz

Copy link
Copy Markdown
Collaborator

This should not be available to contributors. I would go as far as to limit this to members of the pretranslator group.

What do you mean by "pretranslator group"?

Batch actions in general are only available to translators.

@flodolo

flodolo commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What do you mean by "pretranslator group"?

There is a pretranslators group used to gate access to the API.

Batch actions in general are only available to translators.

In this case, I don't think it should. We want visibility on which projects have pretranslation enabled, and check quality.

@mathjazz

Copy link
Copy Markdown
Collaborator

Could you elaborate in more detail a bit on how you envision that to work? How would I as a translator join the group?

In this case, I don't think it should. We want visibility on which projects have pretranslation enabled, and check quality.

Why is that not possible if pretranslation is available to translators or managers?

@flodolo

flodolo commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Can we move this conversation to the issue?

How would I as a translator join the group?

They wouldn't, that's a manually curated group, because the associated API has a cost and can be abused.

Pretranslation is enabled on a locale+project base with strict criteria. Why would we suddenly change this, through batch actions of all places?
https://mozilla-l10n.github.io/localizer-documentation/tools/pretranslation.html#opt-in-guidelines

Why is that not possible if pretranslation is available to translators or managers?

Pretranslation is not available to translators or managers. Pretranslation is enabled on a project and locale, and by default will translate all resources in the project: what's the goal of having a batch action?

@flodolo

flodolo commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@MundiaNderi
You mentioned you had errors locally. Could you add them?

@flodolo

flodolo commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Looks like it was posted in the wrong PR? #4406 (comment)

ValueError at /batch-edit-translations/

A @fluent-fn attribute is required for :platform

Exception Location: /usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py, line 507, in function_ref

Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.13/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/pontoon/batch/views.py", line 131, in batch_edit_translations
action_status = pretranslate_translations(user, locale, entities)
File "/app/pontoon/batch/actions.py", line 436, in pretranslate_translations
pretranslation = get_pretranslation(entity, locale)
File "/app/pontoon/pretranslation/pretranslate.py", line 85, in get_pretranslation
pt_res = pt.serialize(value, properties)
File "/app/pontoon/pretranslation/pretranslate.py", line 185, in serialize
return as_string(self.format, entry, fluent_escape_syntax=False)
File "/app/pontoon/sync/formats/init.py", line 62, in as_string
fluent_entry = fluent_astify_entry(
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 202, in fluent_astify_entry
value = fluent_astify_message(
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 312, in fluent_astify_message
selector = value(message.declarations, message.selectors[len(keys0) - 1])
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 528, in value
return expression(decl, decl[val.name], val.name)
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 444, in expression
return function_ref(decl, arg, expr)
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 507, in function_ref
raise ValueError(f"A @fluent-fn attribute is required for :{function}")

Exception Type: ValueError at /batch-edit-translations/
Exception Value: A @fluent-fn attribute is required for :platform

Can it be that you run the migration with an old version of moz-l10n, and that didn't fix existing strings with PLATFORM()?

See #4533 (comment)

@MundiaNderi

Copy link
Copy Markdown
Collaborator Author

Looks like it was posted in the wrong PR? #4406 (comment)

ValueError at /batch-edit-translations/

A @fluent-fn attribute is required for :platform

Exception Location: /usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py, line 507, in function_ref

Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.13/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/pontoon/batch/views.py", line 131, in batch_edit_translations
action_status = pretranslate_translations(user, locale, entities)
File "/app/pontoon/batch/actions.py", line 436, in pretranslate_translations
pretranslation = get_pretranslation(entity, locale)
File "/app/pontoon/pretranslation/pretranslate.py", line 85, in get_pretranslation
pt_res = pt.serialize(value, properties)
File "/app/pontoon/pretranslation/pretranslate.py", line 185, in serialize
return as_string(self.format, entry, fluent_escape_syntax=False)
File "/app/pontoon/sync/formats/init.py", line 62, in as_string
fluent_entry = fluent_astify_entry(
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 202, in fluent_astify_entry
value = fluent_astify_message(
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 312, in fluent_astify_message
selector = value(message.declarations, message.selectors[len(keys0) - 1])
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 528, in value
return expression(decl, decl[val.name], val.name)
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 444, in expression
return function_ref(decl, arg, expr)
File "/usr/local/lib/python3.13/site-packages/moz/l10n/formats/fluent/serialize.py", line 507, in function_ref
raise ValueError(f"A @fluent-fn attribute is required for :{function}")

Exception Type: ValueError at /batch-edit-translations/
Exception Value: A @fluent-fn attribute is required for :platform

Can it be that you run the migration with an old version of moz-l10n, and that didn't fix existing strings with PLATFORM()?

See #4533 (comment)

Ah yes - the 'wrong PR' was what I had open during the meeting. I will look into the new issue and see if there's any correlation, then revert, possibly tomorrow evening / Friday.

Batch actions: Add the ability to pretranslate strings

This is a draft pr because I want to context switch

Allows contributors to manually batch pretranslate strings
for locales supported by translation engines.
candidate fails to parse, rather than failing the whole batch.
Mirrors the existing behavior in pretranslation/tasks.py
EditorMenu only renders when no entities are batch-selected, so
requestInProgress === 'pretranslate' can never coincide with it being
mounted. In-progress feedback already exists in Pretranslate.tsx.
pretranslation candidate or an unparsable one
@MundiaNderi
MundiaNderi marked this pull request as ready for review September 23, 2026 08:47

@flodolo flodolo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have #4526 to align the background task with the API, but we should probably run bulk_run_checks() to avoid storing a pretranslation with warnings/errors.

Comment thread pontoon/batch/actions.py
for which pretranslation is not enabled by the admins.
"""

entity_pks_with_translation = set(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is excluding approved translations, but it's going to pretranslate strings that already have a pretranslation. We should probably exclude those by filtering the authors (pt_authors = get_pretranslation_authors()).

That means also renaming this variable, e.g. excluded_entity_pks.

Again, flagging @mathjazz for an opinion. Since we want to change the behavior for the task, we might want to pretranslate strings with pending suggestions .filter(Q(approved=True) | Q(user__in=pt_authors.values())).

Comment thread pontoon/batch/actions.py
fuzzy=False,
pretranslated=True,
active=entity.pk not in already_active_entity_pks,
user=user,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Waiting for @mathjazz opinion, but I think we shouldn't attribute this to the user running pretranslation, but to tm or gt, like we do when running pretranslation as a task. At that point, updating badge levels is unnecessary.

In case, the same applies later for the actionlog.

@MundiaNderi MundiaNderi Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed the badge updates. Happy to revisit attributing pretranslation to tm/gt next week in a follow-up if @mathjazz thinks it's worth it.

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.

Add ability to manually pretranslate strings

4 participants