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


##########
superset-frontend/scripts/po2json.sh:
##########
@@ -30,8 +30,8 @@ do
   filename="${file%.*}"
   if [ $extension == "po" ]
   then
-    echo "po2json --domain superset --format jed $file $filename.json"
-    po2json --domain superset --format jed --fuzzy $file $filename.json
+    echo "po2json-cli.js --domain superset $file $filename.json"
+    node scripts/po2json-cli.js --domain superset $file $filename.json

Review Comment:
   **Suggestion:** Unquoted PO and JSON paths are split on whitespace and 
expanded by the shell, so a translation path containing spaces can make 
conversion fail or target the wrong file.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Possible bug`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=69e70f30d5ff411894530815b45d379a&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=69e70f30d5ff411894530815b45d379a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/scripts/po2json.sh
   **Line:** 34:34
   **Comment:**
        *Possible Bug: Unquoted PO and JSON paths are split on whitespace and 
expanded by the shell, so a translation path containing spaces can make 
conversion fail or target the wrong file.
   
   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%2F44742&comment_hash=16a2e2e52b761e1b2323a9b3f605d92a597a3595e35dbc96aba149a81e38762a&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44742&comment_hash=16a2e2e52b761e1b2323a9b3f605d92a597a3595e35dbc96aba149a81e38762a&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset-frontend/scripts/po2json.js:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Converts a .po translation file into the Jed 1.x JSON language pack our
+// frontend runtime (packages/superset-core/src/translation/Translator.ts,
+// via the `jed` package) loads directly. Replaces the old `po2json` CLI
+// (long abandoned, and the sole reason `underscore`'s
+// GHSA-cf4h-3jhx-xvhq/CVE-2021-23358 stayed in this repo's dependency tree
+// via po2json -> nomnom -> underscore, see apache/superset/security/
+// dependabot/9): this only needs gettext-parser, which is what every
+// po2json fork already wraps, so wrapping it ourselves avoids depending on
+// yet another narrow, thinly-maintained po2json-shaped package.
+//
+// Jed's own translate().fetch() already falls back to the original msgid
+// when a key is missing or its stored msgstr is empty (verified directly
+// against the `jed` package this repo ships), so an untranslated entry is
+// included here exactly as gettext-parser parsed it -- no msgid backfill
+// needed to get a correct fallback at render time.
+//
+// Pure library, no CLI/file-system side effects, so it can be unit tested
+// directly (spec/scripts/po2json.test.ts) -- see po2json-cli.js for the
+// script po2json.sh actually invokes.
+
+import { po } from 'gettext-parser';
+
+// gettext-parser preserves each PO file's own header key casing verbatim
+// (conventionally "Language"/"Plural-Forms", Title-Case, not lowercased
+// despite what its README says) -- look up case-insensitively so a file
+// using different casing doesn't silently lose its language/plural rule.
+function findHeader(headers, name) {
+  const key = Object.keys(headers).find(
+    k => k.toLowerCase() === name.toLowerCase(),
+  );
+  return key ? headers[key] : undefined;
+}
+
+/**
+ * @param {Buffer} poBuffer
+ * @param {string} domain
+ * @returns {{
+ *   domain: string,
+ *   locale_data: Record<string, Record<string, string[] | {
+ *     domain: string, lang: string, plural_forms: string,
+ *   }>>,
+ * }}
+ */
+export function poToJed(poBuffer, domain) {
+  const parsed = po.parse(poBuffer);
+  const context = parsed.translations[''] ?? {};

Review Comment:
   **Suggestion:** Only the default context is copied, so every valid PO entry 
with `msgctxt` is omitted from the generated Jed catalog and cannot be 
translated.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=ab499f4fe5b34f01b4491f8dda06bc8a&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=ab499f4fe5b34f01b4491f8dda06bc8a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/scripts/po2json.js
   **Line:** 65:65
   **Comment:**
        *Api Mismatch: Only the default context is copied, so every valid PO 
entry with `msgctxt` is omitted from the generated Jed catalog and cannot be 
translated.
   
   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%2F44742&comment_hash=dc8ab72021c409dd7db867092db6e2d9bd2a3c95a7bd883b88f6f187ceec1b17&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44742&comment_hash=dc8ab72021c409dd7db867092db6e2d9bd2a3c95a7bd883b88f6f187ceec1b17&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