codeant-ai-for-open-source[bot] commented on code in PR #41828:
URL: https://github.com/apache/superset/pull/41828#discussion_r3567862335


##########
scripts/translations/babel_update.sh:
##########
@@ -92,4 +92,33 @@ do
   fi
 done
 
+# A few UI labels ("% calculation" etc.) parse as accidentally-valid
+# %-format directives (a space flag plus a conversion character), so
+# babel auto-flags them python-format on every write and msgfmt then
+# fatals on their translations. The app never %-formats them; strip the
+# flag AFTER the update pass (babel re-adds it during the update, so
+# this must run last). Line-targeted so canonical wrapping is untouched.
+python3 - <<'PYEOF'
+import glob
+
+TARGETS = {'msgid "% calculation"\n', 'msgid "% of parent"\n', 'msgid "% of 
total"\n'}
+paths = ["superset/translations/messages.pot"] + sorted(
+    glob.glob("superset/translations/*/LC_MESSAGES/messages.po")
+)
+for path in paths:
+    lines = open(path).readlines()
+    changed = False
+    for i, line in enumerate(lines):
+        if line in TARGETS and i > 0 and lines[i - 1].startswith("#,"):
+            tokens = [t.strip() for t in lines[i - 1][2:].split(",")]
+            if "python-format" in tokens:
+                tokens = [t for t in tokens if t != "python-format"]
+                if "no-python-format" not in tokens:
+                    tokens.append("no-python-format")
+                lines[i - 1] = "#, " + ", ".join(tokens) + "\n"
+                changed = True
+    if changed:
+        open(path, "w").writelines(lines)

Review Comment:
   **Suggestion:** The Python post-processing reads and writes `.po/.pot` files 
without an explicit UTF-8 encoding, so on systems where the default locale 
encoding is not UTF-8 this can raise decode/encode errors or corrupt non-ASCII 
translations. Open files with `encoding="utf-8"` for both read and write paths. 
[type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ `babel_update.sh` fails on non-UTF-8 locales.
   - ⚠️ Translation tooling depends on host locale configuration.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `scripts/translations/babel_update.sh` and locate the embedded 
Python block that
   post-processes catalogs at lines 32-52, in particular `lines = 
open(path).readlines()` and
   `open(path, "w").writelines(lines)` (shown by the PR hunk as lines 109-121).
   
   2. Confirm that these `open(path)` calls do not pass an `encoding` argument, 
so they use
   Python’s default text encoding derived from the process locale; verify that 
the `.pot`
   header `Content-Type: text/plain; charset=utf-8` in 
`superset/translations/messages.pot`
   (lines 32-34) declares UTF-8 content.
   
   3. From the project root, run the documented workflow under a non-UTF-8 
locale, for
   example `LC_ALL=C LANG=C ./scripts/translations/babel_update.sh`, which is 
the command
   recommended in `scripts/translations/check_translation_regression.py` lines 
16-19 and in
   `docs/.../contributing/howtos.mdx` lines 14-16.
   
   4. When the Python block runs, it iterates `paths` over
   `superset/translations/messages.pot` and all `messages.po` files; as soon as 
it reaches a
   catalog containing non-ASCII UTF-8 bytes, `open(path).readlines()` attempts 
to decode
   using the ASCII default and raises `UnicodeDecodeError`, causing the Python 
process to
   fail and the catalog post-processing to abort due to the locale-dependent 
encoding.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a986a533087f4051839b808209dddcae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a986a533087f4051839b808209dddcae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** scripts/translations/babel_update.sh
   **Line:** 109:121
   **Comment:**
        *Type Error: The Python post-processing reads and writes `.po/.pot` 
files without an explicit UTF-8 encoding, so on systems where the default 
locale encoding is not UTF-8 this can raise decode/encode errors or corrupt 
non-ASCII translations. Open files with `encoding="utf-8"` for both read and 
write paths.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41828&comment_hash=6aa60b8cfe24f4f3413b0272a87befffaaf257f27b22ded1c337a9331d1ad831&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41828&comment_hash=6aa60b8cfe24f4f3413b0272a87befffaaf257f27b22ded1c337a9331d1ad831&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to