You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/09/28 06:24:13 UTC
[PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
rusackas opened a new pull request, #44742:
URL: https://github.com/apache/superset/pull/44742
### SUMMARY
`apache/superset/security/dependabot/9` (`underscore`, GHSA-cf4h-3jhx-xvhq / CVE-2021-23358, critical) stayed unresolved for years because it only ever reached this repo transitively, via `po2json` -> `nomnom` -> `underscore`. #44457 fixed that by swapping in `@hainenber/po2json`, a real fix, but a two-week-old, single-maintainer fork with no track record — the kind of dependency this repo shouldn't lean on long-term.
Every `po2json` fork (the original, `@hainenber`'s, `@connectedcars`'s, ...) is really just a thin CLI wrapper around `gettext-parser` (actively maintained, ~3.9M downloads/month) plus a PO → Jed-JSON transform of maybe 40 lines. This replaces the fork with that transform, written and owned in-repo instead of depending on yet another narrow, po2json-shaped package:
- `scripts/po2json.js` — pure library, `poToJed(poBuffer, domain)` → Jed 1.x language pack. Unit tested directly (`spec/scripts/po2json.test.ts`) against the real `gettext-parser` package, not a mock.
- `scripts/po2json-cli.js` — thin CLI wrapper `po2json.sh` calls; no testable logic of its own.
- `gettext-parser`'s header keys keep each PO file's own casing (its README claims they're lowercased — they aren't), looked up case-insensitively so a differently-cased file doesn't silently lose its `Language`/`Plural-Forms` value.
- An untranslated entry is included exactly as `gettext-parser` parsed it (including an empty `msgstr`), rather than backfilled with the English source text the way some po2json forks do for empty plural forms — verified directly against the `jed` package this repo ships that `translate().fetch()` already falls back to the original `msgid`/`msgid_plural` whenever the stored value is empty or the key is missing entirely, so backfilling would be a no-op.
`underscore`, `nomnom`, `po2json`, `@hainenber/po2json`, `commander` and `gettext-to-messageformat` are all gone from `package-lock.json`.
### TESTING INSTRUCTIONS
```
npx jest spec/scripts/po2json.test.ts packages/superset-core/src/translation
npm run build-translation
```
- Verified byte-for-byte equivalent (modulo the harmless empty-vs-English-prefilled-plural difference explained above) against real `po2json` output across German (2-form plural rule), Russian (3-form), Arabic (6-form), and Chinese (fully untranslated file).
- `npm run build-translation` regenerates all 30 `messages.json` files cleanly.
- Confirmed directly against the `jed` package that both a missing key and a key with an empty `msgstr` correctly fall back to the original source string at render time.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [x] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #44742:
URL: https://github.com/apache/superset/pull/44742
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44742:
URL: https://github.com/apache/superset/pull/44742#issuecomment-5864615392
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44742:
URL: https://github.com/apache/superset/pull/44742#issuecomment-5877075547
**Bito Automatic Review Skipped – PR Already Merged**<br/><br/>Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.<br/>No action is needed if you didn't intend to review it. To get a review, you can type `/review` in a comment and save it
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "hainenber (via GitHub)" <gi...@apache.org>.
hainenber commented on code in PR #44742:
URL: https://github.com/apache/superset/pull/44742#discussion_r4123265008
##########
superset-frontend/scripts/po2json-cli.js:
##########
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+/*
+ * 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.
+ */
+
+// Thin CLI wrapper around po2json.js's poToJed(), called by po2json.sh.
+// Usage: po2json-cli.js --domain <domain> <input.po> <output.json>
+
+import { readFileSync, writeFileSync } from 'node:fs';
+import { poToJed } from './po2json.js';
+
+function parseArgs(argv) {
Review Comment:
IMO, I don't think this file is necessary here. You can utilize the native Node's `util.parseArgs` to achieve the same functionality below with less code.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #44742:
URL: https://github.com/apache/superset/pull/44742#discussion_r4124659242
##########
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:
Good catch — fixed, now folding every msgctxt bucket in under `context\u0004msgid` (Jed's own context_delimiter convention).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
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`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](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) [](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`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](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) [](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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #44742:
URL: https://github.com/apache/superset/pull/44742#issuecomment-5864637108
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | b3ad85a3ca8776882e981e0292db869a450ee189 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6aba080e7fc55e00076eb767 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-44742--superset-docs-preview.netlify.app](https://deploy-preview-44742--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DctBCgIxDEbhu2RtmSBMK97AY6Sd36mik5AJqIh3t7u3eN-XzPVpQWeiA1WXrfXRratjcthDGpLp8b7rll636GlFBN6RTHyHD7SMSz-XZbAsVfjEKNc2z2DmklFLLvT7Aw) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-44742--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] chore(dev-deps): drop po2json entirely, build .po->Jed JSON on gettext-parser [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #44742:
URL: https://github.com/apache/superset/pull/44742#discussion_r4124659242
##########
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:
Good catch — fixed, now folding every msgctxt bucket in under Jed's own context-delimiter key (context + U+0004 + msgid).
##########
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:
Fixed, quoted both paths in the invocation and the oxfmt realpath call.
##########
superset-frontend/scripts/po2json-cli.js:
##########
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+/*
+ * 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.
+ */
+
+// Thin CLI wrapper around po2json.js's poToJed(), called by po2json.sh.
+// Usage: po2json-cli.js --domain <domain> <input.po> <output.json>
+
+import { readFileSync, writeFileSync } from 'node:fs';
+import { poToJed } from './po2json.js';
+
+function parseArgs(argv) {
Review Comment:
Fair point, switched to util.parseArgs — thanks @hainenber.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org