Skip to content

i18n: Move translations to ui/public and enable dynamic loading to reduce bundle size #51735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 20, 2025

Conversation

choo121600
Copy link
Contributor

@choo121600 choo121600 commented Jun 14, 2025

Summary

  • Moved all translation (i18n) files from ui/src/i18n/locales to ui/public/i18n/locales.
  • Adopted i18next-http-backend to load translation files via HTTP dynamically.
  • Updated FastAPI static file serving logic to ensure translation files are accessible in both dev and prod environments.
    • Unified i18next loadPath to /static/i18n/locales/{{lng}}/{{ns}}.json for both environments.
  • Improved maintainability and scalability of the i18n system.

Details

  • i18next-http-backend allows translation files to be loaded on demand, reducing the initial bundle size and supporting dynamic language/namespace loading.
  • FastAPI dev mode now mounts the public i18n directory to /static/i18n, ensuring translation files are served correctly during development.
  • Production mode continues to serve translation files from the built dist directory.
  • The i18n config (config.ts) was updated to use a unified HTTP path for translation files, simplifying the frontend logic.

Before

image

✓ 3627 modules transformed.
dist/.vite/manifest.json                0.45 kB │ gzip:     0.21 kB
dist/index.html                         0.50 kB │ gzip:     0.32 kB
dist/assets/FailedLogs-BGPSeqnE.js      1.70 kB │ gzip:     0.90 kB
dist/assets/index-DQ137obh.js       4,359.84 kB │ gzip: 1,301.55 kB

After

image

✓ 3589 modules transformed.
dist/index.html                               0.50 kB │ gzip:     0.32 kB
dist/.vite/manifest.json                      0.69 kB │ gzip:     0.25 kB
dist/assets/FailedLogs-BKux9o7Z.js            1.70 kB │ gzip:     0.90 kB
dist/assets/browser-ponyfill-BvFGHPkG.js     10.26 kB │ gzip:     3.50 kB
dist/assets/index-C6hLGF4h.js             4,268.63 kB │ gzip: 1,269.05 kB

Breaking Changes

  • If we have custom scripts or tools that expect translation files in src, please update them to use the new location in public/i18n/locales.

closes: #51123

Opened a new PR to avoid potential issues with translation file conflicts in the previous one.
Sorry for the inconvenience.


^ 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.

Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me (except one sanity question)

@jscheffl
Copy link
Contributor

Looks good for me (except one sanity question)

(as wel as CI needs to turn green :-D)

@choo121600 choo121600 force-pushed the feature/i18n-http-backend branch 2 times, most recently from 1105721 to f82036d Compare June 14, 2025 21:45
Copy link
Member

@ashb ashb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a lot of unrelated changes which makes the diff hard to review

@choo121600 choo121600 force-pushed the feature/i18n-http-backend branch from cf338f9 to e09be62 Compare June 15, 2025 07:39
@choo121600 choo121600 force-pushed the feature/i18n-http-backend branch from f7e3bba to 6376d32 Compare June 19, 2025 19:03
@choo121600
Copy link
Contributor Author

I don't understand why this Tests AMD / Airflow CTL tests / airflow-ctl:P3.9 tests (pull_request) CI suddenly started failing.

@choo121600
Copy link
Contributor Author

  1. Resolved conflicts in translation files and applied i18nRules.

    • Previously, i18nRules were not applied, so formatting was inconsistent. In this commits, applying the rules resulted in automatic formatting corrections in some translation files.
  2. Moved check_translations_completeness.py to dev/i18n/check_translations_completeness.py.

    • Since this script is a development tool, having it under public was inappropriate. I moved it to the dev directory instead. If you think there's a better location, feel free to suggest it.
  3. Initially, I planned to move public/i18n/README.md along with the script to dev,
    but since it could reduce visibility and accessibility for translation contributors, I decided to keep it in public.
    I also updated the command path in section "8.1. Checking completeness of i18n files" to reflect the script location.

@choo121600
Copy link
Contributor Author

@pierrejeambrun , Thank you for reviewing my PR ;)

I’ve resolved all the conflicts, and as previously discussed,
I went ahead and moved the check_translations_completeness.py script under dev/i18n instead of leaving it in ui/public/i18n, since this wasn’t fully decided in the discussion but seemed like a better fit (and having a dev script inside the ui directory felt a bit out of place as well).

The CI checks for these changes have also just passed.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic !

@potiuk potiuk merged commit b38e896 into apache:main Jun 20, 2025
98 checks passed
@potiuk
Copy link
Member

potiuk commented Jun 20, 2025

Wooohooo !

@choo121600
Copy link
Contributor Author

Finally!
Huge thanks to everyone who helped review this PR ;)

@choo121600 choo121600 deleted the feature/i18n-http-backend branch June 20, 2025 08:15
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! #protm

RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Jun 21, 2025
…reduce bundle size (apache#51735)

* Feat(i18n): Move translation files to public, use i18next-http-backend

* Adopted i18next-http-backend

* Fix(i18n): Update locales directory path to public for translation files

* Fix(i18n): Update static file path for translation locales

* Fix(i18n): Update translation config file path

* Fix(i18n): Update ESLint configuration to include jsonc-parser

* Fix(i18n): Update ESLint file patterns and add 'components' to namespaces

* Fix(i18n): Initialize i18n(en) in DagCard tests

* chore: enforce consistent array type syntax per @typescript-eslint rule

* Revert "chore: enforce consistent array type syntax per @typescript-eslint rule"

This reverts commit d218738.

* Fix(i18n): Ignore i18n locale files in ESLint TypeScript rules

* Fix(tests): Remove unused imports and clean up test setup

* Apply pre-commit formatting to openapi-gen/ files as per apache#51755

* Fix(eslint): Update i18n and TypeScript rules configuration

* Apply ESLint and i18nRule

* Mov Arabic and French translations to public

* Fix: Update translation file paths to public directory

* Moved i18n doc and completeness checker script from public to dev/i18n

* fix(i18n): i18n policy document translation completeness check command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API area:dev-tools area:UI Related to UI/UX. For Frontend Developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i18n - Load translation files from a backend
8 participants