Skip to content

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

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

MundiaNderi wants to merge 2 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 79.31034% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.20%. Comparing base (e852341) to head (9f335e9).
⚠️ Report is 17 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?

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.
@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.

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