Skip to content

Don't let one failed entity abort pretranslation - #4406

Merged
mathjazz merged 4 commits into
mozilla:mainfrom
mathjazz:4386-pretranslation-parse-failure
Aug 22, 2026
Merged

mathjazz merged 4 commits into
mozilla:mainfrom
mathjazz:4386-pretranslation-parse-failure

Conversation

@mathjazz

@mathjazz mathjazz commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fix #4386.

This is two things:

  1. aeef59b prevents failed entity pretranslation from ending the entire sync task, and includes entity & locale details in the in the error.
  2. fa7df24 is a long shot attempt to fix the error that caused the "Source is not a Fluent entry" error in cy Thunderbird pretranslation.

A pretranslation is serialized with Fluent syntax escaping off, so a TM
or MT result carrying an unescaped brace produces a string that
`parse_source_string_to_json` rejects with "Source is not a Fluent
entry". That call was unguarded, unlike the `get_pretranslation` calls
above it, so a single entity ended the whole project's pretranslation,
which surfaced as a sync failure and left the remaining locales
unpretranslated.

Skip the entity instead, and name the entity and locale in all three
log messages.
Machine translation returns plain text, which can hold braces that are
not Fluent syntax: a stray `{`, or a `{$0}` placeholder marker echoed
back for a leaf that has no placeables. Serialized raw, as pretranslation
does to keep verbatim placeables intact, those produce an entry that
fails to parse with "Source is not a Fluent entry".

Re-serialize with syntax escaping when the raw output doesn't parse. The
braces then survive as literal text instead of the whole pretranslation
being lost. Escaping is a fallback rather than the default because it
would also turn a placeable the service returned verbatim into literal
text.
@mathjazz mathjazz changed the title 4386 pretranslation parse failure Don't let one failed entity abort pretranslation Aug 13, 2026
@mathjazz
mathjazz requested a review from eemeli August 15, 2026 10:29
Comment on lines +412 to +415
# The `title` value here is hacky, but demonstrates that a Google Translate
# response that includes an unexpected `{$0}` does not cause a failure, just
# odd output. `$0` is not a valid Fluent identifier, so the braces are
# escaped to keep the entry parseable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sigh.

Comment on lines 420 to 422
title = { "{" }$0{ "}" } gt_translation
.label = { $brand } gt_translation
.accesskey = g

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this test proposing that something like this should ever be output from pretranslation? If we get garbage like this, why aren't we just giving up on pretranslating this message?

Comment thread pontoon/pretranslation/tasks.py Resolved
Comment thread pontoon/pretranslation/tasks.py Resolved
Comment thread pontoon/pretranslation/tasks.py Resolved
@flodolo

flodolo commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

2. is a long shot attempt to fix the error that caused the "Source is not a Fluent entry" error in cy Thunderbird pretranslation.

One thing not clear to me: were you able to confirm that this was caused by a malformed translation? The fix seems very specific.

@mathjazz

Copy link
Copy Markdown
Collaborator Author

One thing not clear to me: were you able to confirm that this was caused by a malformed translation? The fix seems very specific.

Nah, I haven't confirmed it. I reverted the second commit. Let's land just the first one, and then we might actually be able to confirm it.

@mathjazz
mathjazz requested a review from eemeli August 21, 2026 17:02
@mathjazz
mathjazz merged commit 096eaef into mozilla:main Aug 22, 2026
7 checks passed
@mathjazz
mathjazz deleted the 4386-pretranslation-parse-failure branch August 22, 2026 10:20
@MundiaNderi

Copy link
Copy Markdown
Collaborator

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

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.

Thunderbird forced sync failing with "Source is not a Fluent entry"

4 participants