Repository navigation
Don't let one failed entity abort pretranslation - #4406
Conversation
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.
| # 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. |
| title = { "{" }$0{ "}" } gt_translation | ||
| .label = { $brand } gt_translation | ||
| .accesskey = g |
There was a problem hiding this comment.
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?
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. |
|
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): Exception Type: ValueError at /batch-edit-translations/ |
Fix #4386.
This is two things:
fa7df24 is a long shot attempt to fix the error that caused the "Source is not a Fluent entry" error in cy Thunderbird pretranslation.