Skip to content

fix(internal): append CHAR_LIMIT to translation descriptions in export script#2417

Open
just1and0 wants to merge 4 commits into
version-10.0.0-beta04from
fix/1613-translation-char-limit
Open

fix(internal): append CHAR_LIMIT to translation descriptions in export script#2417
just1and0 wants to merge 4 commits into
version-10.0.0-beta04from
fix/1613-translation-char-limit

Conversation

@just1and0

Copy link
Copy Markdown
Contributor

Summary

  • Updates export_translations.py to automatically append [CHAR_LIMIT=xxx] to each translation_description that doesn't already have one
  • Limit defaults to ~1.5x the English string length, rounded up to the nearest 5
  • Handles plurals <item> tags individually (each item gets its own limit)
  • Decodes XML entities (&amp;&) and Android escape sequences (\', \n,  ) before calculating visible text length
  • Preserves existing manually-set [CHAR_LIMIT=...] values
  • Fixes Python 2 print statement for Python 3 compatibility

Fixes #1613

Test plan

  • Run python3 scripts/translations/export_translations.py and verify CHAR_LIMIT is appended to all descriptions with visible text
  • Verify strings with existing [CHAR_LIMIT=...] are not modified
  • Verify empty override strings (e.g. fui_error_invalid_credentials) are correctly skipped
  • Verify plurals items each get their own CHAR_LIMIT

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the translation export script to automatically calculate and append character limits ([CHAR_LIMIT=xxx]) to translation descriptions. It introduces utility functions to strip XML tags, decode entities, and calculate the character limit based on the English text length. Feedback on these changes highlights opportunities to make the regular expressions more robust. Specifically, simplifying the string and item value patterns using re.DOTALL will prevent failures on other formatting tags, and using re.sub for plurals will correctly handle multi-line <item> tags.

Comment thread scripts/translations/export_translations.py Outdated
Comment thread scripts/translations/export_translations.py
…t script

Fixes #1613 by updating the export_translations script to automatically
calculate and append [CHAR_LIMIT=xxx] to each translation_description
that doesn't already have one. The limit defaults to ~1.5x the English
string length, rounded up to the nearest 5. Also fixes Python 2 print
statement for Python 3 compatibility.
…t script

Fixes #1613 by updating the export_translations script to automatically
calculate and append [CHAR_LIMIT=xxx] to each translation_description
that doesn't already have one. The limit defaults to ~1.5x the English
string length, rounded up to the nearest 5. Handles plurals items
individually, decodes XML entities and Android escape sequences for
accurate length calculation, and preserves existing manual limits.
Also fixes Python 2 print statement for Python 3 compatibility.
@just1and0
just1and0 changed the base branch from master to version-10.0.0-beta04 July 24, 2026 09:45
@demolaf

demolaf commented Jul 24, 2026

Copy link
Copy Markdown
Member

Did a second pass with an agent, maybe worth checking?

Comment:

_extract_visible_text only trims the outer edges, so internal newlines/indentation from wrapped multi-line <string> tags get counted as visible characters — e.g. fui_welcome_back_idp_prompt comes out to CHAR_LIMIT=100 when the actual rendered text is ~56 chars (limit should be ~85). Worth collapsing internal whitespace (e.g. re.sub(r'\s+', ' ', text).strip()) before measuring length, since inflated limits defeat the purpose of this PR for exactly the long/wrapped strings where an accurate limit matters most.

@just1and0
just1and0 force-pushed the fix/1613-translation-char-limit branch from e510af5 to 466f2b7 Compare July 24, 2026 10:14

@russellwheatley russellwheatley left a comment

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.

A couple of bits of feedback on the char limit calc

Comment thread scripts/translations/export_translations.py
Comment thread scripts/translations/export_translations.py Outdated
Comment thread scripts/translations/export_translations.py Outdated
- Collapse whitespace runs to single space before measuring visible text
  length, matching Android's rendering behavior
- Scope CHAR_LIMIT existence check to translation_description attribute
  only, preventing false matches in nested xliff:g descriptions
- Use single-pass regex for XML entity decoding to avoid mangling
  double-encoded entities like &amp;lt;
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.

Translation script needs to be updated

3 participants