Skip to content

[WIP]feat(i18n): add tool to detect unused translation keys#58661

Closed
RoyLee1224 wants to merge 1 commit intoapache:mainfrom
RoyLee1224:i18n-unused
Closed

[WIP]feat(i18n): add tool to detect unused translation keys#58661
RoyLee1224 wants to merge 1 commit intoapache:mainfrom
RoyLee1224:i18n-unused

Conversation

@RoyLee1224
Copy link
Contributor

@RoyLee1224 RoyLee1224 commented Nov 25, 2025

Why

As the Airflow UI grows, translation files accumulate keys that are no longer used in the source code. This tool helps developers maintain the cleanliness of translation files.

Note: I'm marking this as a draft since this is just the first phase. The code has not yet been refactored, and the detection logic still needs some improvement. Feedback and discussion are welcome!

Key Features

  1. Static Analysis: Scans .ts and .tsx files in airflow/ui to find usages of translate().
  2. Dynamic Key Support:
    • Task/DAG states (e.g., state.${taskState} expands to state.success, state.failed, etc.).
    • Directions (up, down, etc.).
  3. Pluralization Handling: Recognizes that using a base key implies usage of its plural forms (task_one, task_other).
  4. Documentation: Updated dev/breeze/doc/breeze_ui.rst and added the command output screenshot.

Implementation Details

  • The script uses Regex to parse translation keys.
  • It compares the keys defined in en/*.json against the keys found in the source code.
  • It reports:
    • Unused: Defined in JSON but not found in code.
    • Undefined: Used in code but missing in JSON.
    • Dynamic Patterns: Lists detected dynamic template literals.

Screenshots

I've verified that these keys in admin.json and assets.json are indeed unused. (For nameMaxLength, it's a key mismatch.)
CleanShot 2025-11-25 at 01 13 04

The detection logic for dynamic key in common.json still needs some refinement. However, I can confirm that at least keys like allOperators and logicalDateFrom are unused and should be removed.
CleanShot 2025-11-25 at 01 13 29

While the detection isn't 100% precise yet, it effectively isolates the potential candidates. Finding these unused keys manually would have been nearly impossible.

CleanShot 2025-11-25 at 01 13 46

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@boring-cyborg boring-cyborg bot added area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch labels Nov 25, 2025
@RoyLee1224 RoyLee1224 marked this pull request as draft November 25, 2025 06:44
@RoyLee1224 RoyLee1224 changed the title [WIP]feat(i18n): add tool to detect and remove unused translation keys [WIP]feat(i18n): add tool to detect unused translation keys Nov 25, 2025
@potiuk potiuk closed this Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants