fix translation length + repair localized /data/

Merged
RI
2mo ago
+315-44

Summary

  • Instruct the edge translation worker to keep translations roughly the same length as the source (±30%) so UI layouts stay intact.
  • Honor translate="no" and class="notranslate" when collecting HTML segments.
  • Protect the Live Update product name and bump TRANSLATION_CACHE_VERSION so stale locale caches refresh.
  • Fix /data/: bootstrap metrics live in an inline JSON script (not a huge attribute), and live metric regions are marked translate="no".
  • Escape bootstrap JSON for script embeds (jsonForInlineScript) so </script> cannot break out of the tag.

Why /fr/data/ was broken

Localized /data/ pages were still serving the pre-#947 loading shell (spinner + empty tables, no bootstrap metrics). English already SSR-boots metrics. All locales (fr, de, es, …) were stuck on that stale translated HTML.

After deploy of web + translation worker, the cache version bump forces a fresh translation of the fixed English page.

Test plan

  • bun run check in apps/translation-worker (parser tests include translate=no)
  • jsonForInlineScript round-trips and blocks </script> breakouts
  • Deploy translation worker, then hit /fr/data/ and confirm SSR tables + no loading shell
  • Confirm chrome copy is translated, metric rows stay English/stable
  • Spot-check that short nav/labels are not expanded into long sentences
Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Improved translation handling for excluded content, markup, attributes, and protected terms such as “Live Update.”
    • Added safeguards for translation length, with retries and source-text fallback when needed.
    • Improved loading and display of data metrics, charts, and tables.
    • Added clearer screen-reader status updates for dynamic data.
  • Bug Fixes

    • Prevented dynamic data and marked content from being translated unintentionally.
    • Improved safe handling of metrics embedded in the data page.