fix(internal): append CHAR_LIMIT to translation descriptions in export script#2417
fix(internal): append CHAR_LIMIT to translation descriptions in export script#2417just1and0 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.
…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.
|
Did a second pass with an agent, maybe worth checking? Comment:
|
e510af5 to
466f2b7
Compare
russellwheatley
left a comment
There was a problem hiding this comment.
A couple of bits of feedback on the char limit calc
- 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 &lt;
Summary
export_translations.pyto automatically append[CHAR_LIMIT=xxx]to eachtranslation_descriptionthat doesn't already have one<item>tags individually (each item gets its own limit)&→&) and Android escape sequences (\',\n,) before calculating visible text length[CHAR_LIMIT=...]valuesprintstatement for Python 3 compatibilityFixes #1613
Test plan
python3 scripts/translations/export_translations.pyand verify CHAR_LIMIT is appended to all descriptions with visible text[CHAR_LIMIT=...]are not modifiedfui_error_invalid_credentials) are correctly skipped