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/07/02 01:24:44 UTC
[PR] feat(i18n): skip do-not-translate entries in backfill_po [superset]
rusackas opened a new pull request, #41651:
URL: https://github.com/apache/superset/pull/41651
### SUMMARY
Follow-up hardening to `scripts/translations/backfill_po.py`. The backfill only checked for an empty `msgstr`, so it filled entries a human translator had **deliberately left blank** — the `ru` catalog carries 21 `# Не переводить` ("do not translate") markers on literal tokens, and the backfill translated them anyway. CodeAnt flagged several on #41649.
These strings must stay identical to the source or they break things / are meaningless to translate:
- **`bolt`** — an icon name (`ControlHeader.tsx` → `label={t('bolt')}` renders the ⚡ icon); a translated value breaks the icon lookup.
- **`step-after` / `step-before`** — d3 line-interpolation enum values.
- **`error_message`** — an API field name.
- **`TEMPORAL_RANGE`, `EMAIL_REPORTS_CTA`** — code constants; SQL keywords (`GROUP BY`, `DELETE`, …); formats/proper nouns (`WFS`, `WMS`, `XYZ`, `ECharts`, `crontab`, `sql`); example placeholders (`superset.example.com`, `your-project-1234-a1`, `schema1,schema2`, `10000`).
**Change:** `_is_do_not_translate(entry)` is consulted when collecting untranslated entries. An entry is skipped if its msgid is in a curated `DO_NOT_TRANSLATE` set (seeded from the `ru` translator's markers — these tokens are language-independent, so the set applies to every catalog) **or** if it carries an explicit do-not-translate translator comment in any catalog (honoring a human's decision, e.g. `# Не переводить`). Skipped entries are reported and left untranslated so they fall back to the source token.
The per-language backfill PRs are being updated to revert these tokens, and the already-merged de/lv/fi catalogs get a follow-up.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — internal tooling.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/scripts/translations/backfill_po_test.py
```
(34 tests pass — adds curated-set, translator-comment, and pass-through cases.)
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [x] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4873748493
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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] feat(i18n): skip do-not-translate entries in backfill_po [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4861421379
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/41651?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 63.83%. Comparing base ([`8be255d`](https://app.codecov.io/gh/apache/superset/commit/8be255de408cd7beafa05b64d4460f353f8bf24e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`fb8af9c`](https://app.codecov.io/gh/apache/superset/commit/fb8af9caec64c083e1485ee010cde71fe9f2be33?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 9 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #41651 +/- ##
==========================================
- Coverage 64.56% 63.83% -0.73%
==========================================
Files 2673 2674 +1
Lines 147634 147710 +76
Branches 34090 34098 +8
==========================================
- Hits 95314 94288 -1026
- Misses 50591 51695 +1104
+ Partials 1729 1727 -2
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.10% <ø> (+0.03%)` | :arrow_up: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.64% <ø> (+0.03%)` | :arrow_up: |
| [python](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.63% <ø> (-1.53%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.47% <ø> (+0.14%)` | :arrow_up: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/41651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/41651?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4888416538
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "hainenber (via GitHub)" <gi...@apache.org>.
hainenber commented on code in PR #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3525364767
##########
scripts/translations/backfill_po.py:
##########
@@ -152,6 +152,61 @@ def _is_missing(entry: polib.POEntry) -> bool:
return not entry.msgstr
+# Canonical registry of msgids that must never be machine-translated: literal
+# tokens compared against source (SQL keywords, confirmation words), enum values
+# (d3 interpolation modes), icon names (e.g. "bolt" -> the ⚡ Explore control
+# icon), API field names, code constants, and example placeholders. Translating
+# them can break icon lookups, enum matching, or API contracts, or is simply
+# meaningless (proper nouns, example values). apply_do_not_translate.py stamps
+# these msgids in messages.pot with a `#. MACHINE_READ-DO_NOT_TRANSLATE`
+# extracted comment that propagates to every catalog on `pybabel update`.
+DO_NOT_TRANSLATE_REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def _load_do_not_translate(path: Path = DO_NOT_TRANSLATE_REGISTRY) -> frozenset[str]:
+ """Load the do-not-translate msgids (skips comment/blank lines).
+
+ Lines are stripped before the blank/comment checks, matching the parsing in
+ apply_do_not_translate.py, so trailing whitespace or an indented comment
+ never yields a msgid that fails to match a catalog entry.
+ """
+ if not path.exists():
+ return frozenset()
+ return frozenset(
+ stripped
+ for line in path.read_text(encoding="utf-8").splitlines()
+ if (stripped := line.strip()) and not stripped.startswith("#")
+ )
+
+
+DO_NOT_TRANSLATE: frozenset[str] = _load_do_not_translate()
+
+# An explicit do-not-translate marker on an entry, matched in either the
+# extracted comment (`#. MACHINE_READ-DO_NOT_TRANSLATE`, the standard propagated
+# from the .pot) or a translator comment (e.g. the ru catalog's legacy
+# "# Не переводить"). Honored so a human's deliberate decision is never
+# overridden even if a msgid is missing from the registry.
+_DO_NOT_TRANSLATE_COMMENT: re.Pattern[str] = re.compile(
+ r"machine_read-do_not_translate|не\s+переводить"
Review Comment:
Can we switch the legacy Russian translator comment to use the standard marker? Or it should be on a follow up 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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3525752666
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
Review Comment:
Annotated it in 14abef6f11.
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
Review Comment:
Annotated it in 14abef6f11.
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
+ out: list[str] = []
+ changed: int = 0
+ for line in lines:
+ if line in targets and (not out or out[-1] != _MARKER_LINE):
+ # `#.` extracted comments precede `msgid`; these registry entries are
+ # bare single-line msgids, so inserting directly above is correct.
+ out.append(_MARKER_LINE)
+ changed += 1
+ out.append(line)
+ if changed:
+ pot_path.write_text("\n".join(out), encoding="utf-8")
+ return changed
+
+
+def main() -> None:
+ """Stamp the marker onto the target .pot from the registry."""
+ pot_path: Path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_POT
+ if not pot_path.exists():
+ print(f"POT file not found: {pot_path}", file=sys.stderr)
+ sys.exit(1)
+ # Fail fast if the registry file is absent: babel_update.sh depends on this
+ # step to stamp the .pot, and continuing would silently publish catalogs
+ # without any do-not-translate markers. An existing-but-empty registry is a
+ # valid state (nothing to mark), so only a missing file is an error.
+ if not REGISTRY.exists():
+ print(
+ f"do-not-translate registry not found at {REGISTRY}; refusing to "
+ "produce unmarked translation artifacts.",
+ file=sys.stderr,
+ )
+ sys.exit(1)
+ registry: set[str] = load_registry()
+ if not registry:
+ print(
+ f"do-not-translate registry {REGISTRY} is empty; nothing to mark.",
+ file=sys.stderr,
+ )
+ return
+ changed = apply_markers(pot_path, registry)
Review Comment:
Annotated it in 14abef6f11.
--
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] feat(i18n): skip do-not-translate entries in backfill_po [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 #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3509908470
##########
scripts/translations/backfill_po.py:
##########
@@ -152,6 +152,60 @@ def _is_missing(entry: polib.POEntry) -> bool:
return not entry.msgstr
+# msgids that must never be machine-translated: literal tokens compared against
+# source (SQL keywords, confirmation words), enum values (d3 interpolation
+# modes), icon names (e.g. "bolt" -> the ⚡ Explore control icon), API field
+# names, code constants, and example placeholders. Seeded from the
+# "# Не переводить" (do-not-translate) markers a human translator curated in the
+# ru catalog; these strings are language-independent, so the set applies to
+# every catalog. Translating them can break icon lookups, enum matching, or API
+# contracts, or is simply meaningless (proper nouns, example values).
+DO_NOT_TRANSLATE: frozenset[str] = frozenset(
+ {
+ "10000",
+ "DELETE",
+ "ECharts",
+ "EMAIL_REPORTS_CTA",
+ "GROUP BY",
+ "NOT GROUPED BY",
+ "OVERWRITE",
+ "TEMPORAL_RANGE",
+ "WFS",
+ "WMS",
+ "XYZ",
+ "bolt",
+ "crontab",
+ "error_message",
+ "pivoted_xlsx",
+ "schema1,schema2",
+ "sql",
+ "step-after",
+ "step-before",
+ "superset.example.com",
+ "your-project-1234-a1",
+ }
+)
+
+# Translator comment (in any catalog) explicitly marking an entry off-limits,
+# e.g. the ru catalog's "# Не переводить". Honored so a human translator's
+# deliberate decision to leave a string untranslated is never overridden.
+_DO_NOT_TRANSLATE_COMMENT = re.compile(
+ r"не\s+переводить|do[\s-]?not[\s-]?translate|don'?t\s+translate",
+ re.IGNORECASE,
+)
Review Comment:
**Suggestion:** Add an explicit type annotation to this newly introduced module-level regex variable. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is newly introduced Python code and the module-level regex variable is assigned without an explicit type annotation, which matches the type-hinting rule for relevant variables that can be annotated.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=81b5b88e47a34d979ee81fa5d11c5e58&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=81b5b88e47a34d979ee81fa5d11c5e58&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/backfill_po.py
**Line:** 192:195
**Comment:**
*Custom Rule: Add an explicit type annotation to this newly introduced module-level regex variable.
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%2F41651&comment_hash=aeec6acb22e118662f3a8ae4d29d467943df44eb839afcf16a117cae92df8265&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=aeec6acb22e118662f3a8ae4d29d467943df44eb839afcf16a117cae92df8265&reaction=dislike'>👎</a>
##########
scripts/translations/backfill_po.py:
##########
@@ -647,6 +701,15 @@ def backfill(
missing: list[polib.POEntry] = [e for e in cat if e.msgid and _is_missing(e)]
print(f"Found {len(missing)} untranslated entries for '{lang}'.", file=sys.stderr)
+ skipped_dnt = [e for e in missing if _is_do_not_translate(e)]
Review Comment:
**Suggestion:** Add a concrete type annotation for this new local collection variable to satisfy the type-hinting rule. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This new local list variable is introduced without an explicit type annotation even though its type is clear, so it fits the custom rule requiring type hints on relevant annotated variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=482582e1a46341f1a6b70bac044f006c&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=482582e1a46341f1a6b70bac044f006c&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/backfill_po.py
**Line:** 704:704
**Comment:**
*Custom Rule: Add a concrete type annotation for this new local collection variable to satisfy the type-hinting rule.
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%2F41651&comment_hash=1f0316dcb9d807a6850ff8c5997470a18b94892d3ea5a17d1c0f398935158fe9&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=1f0316dcb9d807a6850ff8c5997470a18b94892d3ea5a17d1c0f398935158fe9&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] feat(i18n): skip do-not-translate entries in backfill_po [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3509915812
##########
scripts/translations/backfill_po.py:
##########
@@ -647,6 +701,15 @@ def backfill(
missing: list[polib.POEntry] = [e for e in cat if e.msgid and _is_missing(e)]
print(f"Found {len(missing)} untranslated entries for '{lang}'.", file=sys.stderr)
+ skipped_dnt = [e for e in missing if _is_do_not_translate(e)]
+ if skipped_dnt:
+ missing = [e for e in missing if not _is_do_not_translate(e)]
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing integration test for DNT filtering</b></div>
<div id="fix">
The `_is_do_not_translate` function has 3 unit tests verifying its logic in isolation (lines 444-464), but no integration test validates that DNT entries are actually skipped when the `backfill()` function runs end-to-end. Without an integration test, regressions in the filter logic (e.g., the filter being applied at the wrong stage, or not being applied at all) would go undetected until the script runs against real `.po` files.
</div>
</div>
<small><i>Code Review Run #502ef6</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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] feat(i18n): do-not-translate registry + '#. do-not-translate' marker standard [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4898228841
@hainenber agreed, the plain pattern wins... standardized in ec3b871f75: the marker is now `#. do-not-translate` across the scripts, docs, tests, and the stamped `messages.pot`. The backfill detection regex already matched that form, so the old prefixed variant is just gone (it never shipped anywhere). Thanks for pushing on 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] feat(i18n): do-not-translate registry + '#. do-not-translate' marker standard [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4899284396
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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] feat(i18n): skip do-not-translate entries in backfill_po [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4861370794
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "hainenber (via GitHub)" <gi...@apache.org>.
hainenber commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4887083783
I'd rather to have `#. do-not-translate` comment to be used as `official gettext "do not translate" flag`. Machines and humans alike would easily recognize the pattern, IMO.
--
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] feat(i18n): do-not-translate registry + '#. do-not-translate' marker standard [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #41651:
URL: https://github.com/apache/superset/pull/41651
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4876084773
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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] feat(i18n): skip do-not-translate entries in backfill_po [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4861378897
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | fb8af9caec64c083e1485ee010cde71fe9f2be33 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a45bddcbb3e2f000874735f |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-41651--superset-docs-preview.netlify.app](https://deploy-preview-41651--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#DcpBCoAgEEDRu8y6IUsr6QYdQx2lyBwxNxHdPXcf_nshF75yhRWgA1tMcntrt3Px_THohPd5ZCTGxBVr-3c01TdLPkd-Nmp6NmqyRM5a6ccghNCLWuQU4PsB) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-41651--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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3530912411
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
Review Comment:
Annotated `line: str` in 3452af96bb.
##########
scripts/translations/backfill_po.py:
##########
@@ -152,6 +152,61 @@ def _is_missing(entry: polib.POEntry) -> bool:
return not entry.msgstr
+# Canonical registry of msgids that must never be machine-translated: literal
+# tokens compared against source (SQL keywords, confirmation words), enum values
+# (d3 interpolation modes), icon names (e.g. "bolt" -> the ⚡ Explore control
+# icon), API field names, code constants, and example placeholders. Translating
+# them can break icon lookups, enum matching, or API contracts, or is simply
+# meaningless (proper nouns, example values). apply_do_not_translate.py stamps
+# these msgids in messages.pot with a `#. MACHINE_READ-DO_NOT_TRANSLATE`
+# extracted comment that propagates to every catalog on `pybabel update`.
+DO_NOT_TRANSLATE_REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def _load_do_not_translate(path: Path = DO_NOT_TRANSLATE_REGISTRY) -> frozenset[str]:
+ """Load the do-not-translate msgids (skips comment/blank lines).
+
+ Lines are stripped before the blank/comment checks, matching the parsing in
+ apply_do_not_translate.py, so trailing whitespace or an indented comment
+ never yields a msgid that fails to match a catalog entry.
+ """
+ if not path.exists():
+ return frozenset()
+ return frozenset(
+ stripped
+ for line in path.read_text(encoding="utf-8").splitlines()
+ if (stripped := line.strip()) and not stripped.startswith("#")
+ )
+
+
+DO_NOT_TRANSLATE: frozenset[str] = _load_do_not_translate()
+
+# An explicit do-not-translate marker on an entry, matched in either the
+# extracted comment (`#. MACHINE_READ-DO_NOT_TRANSLATE`, the standard propagated
+# from the .pot) or a translator comment (e.g. the ru catalog's legacy
+# "# Не переводить"). Honored so a human's deliberate decision is never
+# overridden even if a msgid is missing from the registry.
+_DO_NOT_TRANSLATE_COMMENT: re.Pattern[str] = re.compile(
+ r"machine_read-do_not_translate|не\s+переводить"
Review Comment:
Checked the ru catalog — all 21 `# Не переводить` msgids are already in the registry, so the standard marker lands there automatically on the next `babel_update.sh` run. Keeping catalog regeneration out of this PR; the legacy comments stay honored by `backfill_po.py` regardless.
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [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 #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3525753970
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
Review Comment:
**Suggestion:** Add an explicit type annotation for this local variable to satisfy the required type-hint coverage for annotatable variables. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The rule requires type hints on relevant annotatable variables in new or modified Python code. This local variable is assigned a string value and can be annotated as `line: str = raw_line.strip()`, so the omission is a real rule violation.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0a178d839d6742658df56a63b3fbda76&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=0a178d839d6742658df56a63b3fbda76&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/apply_do_not_translate.py
**Line:** 61:61
**Comment:**
*Custom Rule: Add an explicit type annotation for this local variable to satisfy the required type-hint coverage for annotatable variables.
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%2F41651&comment_hash=c2782e7e2bf5c7e52d2ae06ca36684cec6d532f310fce6ffaf8fad20bdd4bb2d&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=c2782e7e2bf5c7e52d2ae06ca36684cec6d532f310fce6ffaf8fad20bdd4bb2d&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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #41651:
URL: https://github.com/apache/superset/pull/41651#issuecomment-4897397569
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3518808256
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
+ out: list[str] = []
+ changed = 0
Review Comment:
Done — annotated `changed: int`.
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
+ out: list[str] = []
+ changed = 0
+ for line in lines:
+ if line in targets and (not out or out[-1] != _MARKER_LINE):
+ # `#.` extracted comments precede `msgid`; these registry entries are
+ # bare single-line msgids, so inserting directly above is correct.
+ out.append(_MARKER_LINE)
+ changed += 1
+ out.append(line)
+ if changed:
+ pot_path.write_text("\n".join(out), encoding="utf-8")
+ return changed
+
+
+def main() -> None:
+ """Stamp the marker onto the target .pot from the registry."""
+ pot_path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_POT
Review Comment:
Done — `pot_path: Path` is annotated.
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
+ out: list[str] = []
+ changed = 0
+ for line in lines:
+ if line in targets and (not out or out[-1] != _MARKER_LINE):
+ # `#.` extracted comments precede `msgid`; these registry entries are
+ # bare single-line msgids, so inserting directly above is correct.
+ out.append(_MARKER_LINE)
+ changed += 1
+ out.append(line)
+ if changed:
+ pot_path.write_text("\n".join(out), encoding="utf-8")
+ return changed
+
+
+def main() -> None:
+ """Stamp the marker onto the target .pot from the registry."""
+ pot_path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_POT
+ if not pot_path.exists():
+ print(f"POT file not found: {pot_path}", file=sys.stderr)
+ sys.exit(1)
+ # Fail fast if the registry file is absent: babel_update.sh depends on this
+ # step to stamp the .pot, and continuing would silently publish catalogs
+ # without any do-not-translate markers. An existing-but-empty registry is a
+ # valid state (nothing to mark), so only a missing file is an error.
+ if not REGISTRY.exists():
+ print(
+ f"do-not-translate registry not found at {REGISTRY}; refusing to "
+ "produce unmarked translation artifacts.",
+ file=sys.stderr,
+ )
+ sys.exit(1)
+ registry = load_registry()
Review Comment:
Done — `registry: set[str]` is annotated.
##########
scripts/translations/babel_update.sh:
##########
@@ -55,6 +55,12 @@ msgcat --sort-by-msgid --no-wrap --no-location superset/translations/messages.po
cat $LICENSE_TMP superset/translations/messages.pot > messages.pot.tmp \
&& mv messages.pot.tmp superset/translations/messages.pot
+# Stamp do-not-translate msgids (superset/translations/do-not-translate.txt) with
+# a `#. MACHINE_READ-DO_NOT_TRANSLATE` extracted comment. Extracted comments
+# propagate from the .pot into every catalog on the `pybabel update` below, so
+# the do-not-translate status stays consistent across all languages.
+python scripts/translations/apply_do_not_translate.py superset/translations/messages.pot
Review Comment:
Good catch — guarded the call with `|| exit 1` so a stamping failure stops the script before `pybabel update` runs.
##########
scripts/translations/backfill_po.py:
##########
@@ -152,6 +152,56 @@ def _is_missing(entry: polib.POEntry) -> bool:
return not entry.msgstr
+# Canonical registry of msgids that must never be machine-translated: literal
+# tokens compared against source (SQL keywords, confirmation words), enum values
+# (d3 interpolation modes), icon names (e.g. "bolt" -> the ⚡ Explore control
+# icon), API field names, code constants, and example placeholders. Translating
+# them can break icon lookups, enum matching, or API contracts, or is simply
+# meaningless (proper nouns, example values). apply_do_not_translate.py stamps
+# these msgids in messages.pot with a `#. MACHINE_READ-DO_NOT_TRANSLATE`
+# extracted comment that propagates to every catalog on `pybabel update`.
+DO_NOT_TRANSLATE_REGISTRY = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def _load_do_not_translate(path: Path = DO_NOT_TRANSLATE_REGISTRY) -> frozenset[str]:
+ """Load the do-not-translate msgids (skips comment/blank lines)."""
+ if not path.exists():
+ return frozenset()
+ return frozenset(
+ line
+ for line in path.read_text(encoding="utf-8").splitlines()
+ if line and not line.startswith("#")
+ )
Review Comment:
Fixed — `_load_do_not_translate` strips lines to match `apply_do_not_translate.py`, and added a unit test covering trailing spaces / indented comments.
--
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] feat(i18n): do-not-translate registry + MACHINE_READ marker standard [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 #41651:
URL: https://github.com/apache/superset/pull/41651#discussion_r3518817611
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
Review Comment:
**Suggestion:** Add an explicit type hint for this local collection variable to satisfy the requirement that relevant variables are annotated. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The rule requires type hints on relevant variables that can be annotated. This local list variable is unannotated, so the suggestion correctly identifies a real violation.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ce2e83b7fae74483baa26ba1b3194cc3&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=ce2e83b7fae74483baa26ba1b3194cc3&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/apply_do_not_translate.py
**Line:** 79:79
**Comment:**
*Custom Rule: Add an explicit type hint for this local collection variable to satisfy the requirement that relevant variables are annotated.
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%2F41651&comment_hash=bdf91641b32288d3dd9836a7df7951ef11b44cb6bbf5881f6fc1ce8bc0428ba8&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=bdf91641b32288d3dd9836a7df7951ef11b44cb6bbf5881f6fc1ce8bc0428ba8&reaction=dislike'>👎</a>
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
Review Comment:
**Suggestion:** Add a type annotation for this derived set variable so it complies with the project’s type-hint requirement for relevant variables. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This set comprehension result is a relevant variable that could be annotated, but it is not. That matches the stated type-hint requirement violation.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1c289dc97aea4216892c457119f9b641&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=1c289dc97aea4216892c457119f9b641&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/apply_do_not_translate.py
**Line:** 80:80
**Comment:**
*Custom Rule: Add a type annotation for this derived set variable so it complies with the project’s type-hint requirement for relevant variables.
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%2F41651&comment_hash=273bd8147d822094dd6d1ace235e1f9377665560b3bbd5aee72467c8e205c91f&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=273bd8147d822094dd6d1ace235e1f9377665560b3bbd5aee72467c8e205c91f&reaction=dislike'>👎</a>
##########
scripts/translations/apply_do_not_translate.py:
##########
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+# 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.
+"""Stamp do-not-translate msgids in a .pot with an extracted-comment marker.
+
+For every msgid listed in ``superset/translations/do-not-translate.txt`` that is
+present in the target .pot, add a ``#. MACHINE_READ-DO_NOT_TRANSLATE`` extracted
+comment. gettext extracted comments (``#.``) propagate from the .pot into every
+language .po on ``pybabel update``, so the do-not-translate status stays
+consistent across all catalogs from a single registry.
+
+Run from ``babel_update.sh`` after the .pot is extracted and normalized (and
+before ``pybabel update``). Idempotent: re-running makes no further changes.
+
+Usage:
+ python scripts/translations/apply_do_not_translate.py [POT_PATH]
+ # POT_PATH defaults to superset/translations/messages.pot
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+# The standardized extracted-comment marker. Kept in sync with backfill_po.py.
+MARKER: str = "MACHINE_READ-DO_NOT_TRANSLATE"
+_MARKER_LINE: str = f"#. {MARKER}"
+
+TRANSLATIONS_DIR: Path = (
+ Path(__file__).parent.parent.parent / "superset" / "translations"
+)
+DEFAULT_POT: Path = TRANSLATIONS_DIR / "messages.pot"
+REGISTRY: Path = TRANSLATIONS_DIR / "do-not-translate.txt"
+
+
+def load_registry(path: Path = REGISTRY) -> set[str]:
+ """Return the set of do-not-translate msgids (skips comments/blank lines).
+
+ Each line is stripped before the blank/comment check, so trailing
+ whitespace or an indented comment never yields a msgid that fails to match
+ the .pot.
+ """
+ if not path.exists():
+ return set()
+ entries: set[str] = set()
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
+ line = raw_line.strip()
+ if line and not line.startswith("#"):
+ entries.add(line)
+ return entries
+
+
+def _escape(msgid: str) -> str:
+ """Escape a msgid the way gettext writes it on a `msgid "..."` line."""
+ return msgid.replace("\\", "\\\\").replace('"', '\\"')
+
+
+def apply_markers(pot_path: Path, registry: set[str]) -> int:
+ """Insert the marker comment above each registry msgid via text edit.
+
+ Text manipulation (rather than a polib round-trip) preserves the .pot's
+ exact wrapping/layout, so the only change is the added marker lines.
+ Idempotent. Returns the number of entries newly marked.
+ """
+ lines = pot_path.read_text(encoding="utf-8").split("\n")
+ targets = {f'msgid "{_escape(m)}"' for m in registry}
+ out: list[str] = []
+ changed: int = 0
+ for line in lines:
+ if line in targets and (not out or out[-1] != _MARKER_LINE):
+ # `#.` extracted comments precede `msgid`; these registry entries are
+ # bare single-line msgids, so inserting directly above is correct.
+ out.append(_MARKER_LINE)
+ changed += 1
+ out.append(line)
+ if changed:
+ pot_path.write_text("\n".join(out), encoding="utf-8")
+ return changed
+
+
+def main() -> None:
+ """Stamp the marker onto the target .pot from the registry."""
+ pot_path: Path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_POT
+ if not pot_path.exists():
+ print(f"POT file not found: {pot_path}", file=sys.stderr)
+ sys.exit(1)
+ # Fail fast if the registry file is absent: babel_update.sh depends on this
+ # step to stamp the .pot, and continuing would silently publish catalogs
+ # without any do-not-translate markers. An existing-but-empty registry is a
+ # valid state (nothing to mark), so only a missing file is an error.
+ if not REGISTRY.exists():
+ print(
+ f"do-not-translate registry not found at {REGISTRY}; refusing to "
+ "produce unmarked translation artifacts.",
+ file=sys.stderr,
+ )
+ sys.exit(1)
+ registry: set[str] = load_registry()
+ if not registry:
+ print(
+ f"do-not-translate registry {REGISTRY} is empty; nothing to mark.",
+ file=sys.stderr,
+ )
+ return
+ changed = apply_markers(pot_path, registry)
Review Comment:
**Suggestion:** Add an explicit type annotation for this local result variable to keep variable typing consistent with the enforced rule. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The local result variable is unannotated even though its type is evident and could be declared. This is a real omission under the Python type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=043be62829484b529a4453d7e66c6311&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=043be62829484b529a4453d7e66c6311&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/apply_do_not_translate.py
**Line:** 119:119
**Comment:**
*Custom Rule: Add an explicit type annotation for this local result variable to keep variable typing consistent with the enforced rule.
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%2F41651&comment_hash=6b33b765d77b54fc8887430162627972051947903802a8ce48d1883b2875bbb2&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41651&comment_hash=6b33b765d77b54fc8887430162627972051947903802a8ce48d1883b2875bbb2&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