Skip to content

i18n - Load translation files from a backend #51123

Closed

Description

@bbovenzi

Description

Right now all of the translation json files are in the UI js bundle at runtime. We should move them to the server and only load the translation currently being used.

The initial PR for i18n left TODO comments for the places we need to change in the UI to handle this.

Use case/motivation

Prevent unnecessary bundle size bloat.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added this to the Airflow 3.1.0 milestone on May 27, 2025
  2. added
    kind:feature
    area:API
    area:UI
    on May 27, 2025
  3. choo121600 commented on May 28, 2025

    @choo121600
    Member

    I'd like to help on this issue. Could you assign it to me? 👀

  4. bbovenzi commented on May 28, 2025

    @bbovenzi
    ContributorAuthor

    @choo121600 go for it!

  5. choo121600 commented on Jun 5, 2025

    @choo121600
    Member

    I'm planning to move the i18n translation files from the UI bundle (airflow-core/src/airflow/ui/src/i18n/locales/{lang}/{ns}.json) to the backend.
    I’d like to get input on the best place to put the directory.

    For example:

    1. api_fastapi/core_api/i18n/locales/{lang}/{ns}.json
    2. api_fastapi/common/static/i18n/locales/{lang}/{ns}.json

    Or would it be better to manage them as a core Airflow resource like airflow-core/src/airflow/i18n/locales/?
    @bbovenzi Do you already have any preferred location in mind?

  6. potiuk commented on Jun 5, 2025

    @potiuk
    Member

    Good idea.

  7. potiuk commented on Jun 5, 2025

    @potiuk
    Member

    If I also may suggest - should we use yaml maybe instead of json? It's simple enough to fix all the scripting we have, and I Find json in this context overly verbose and prone to errors (especially when you copy lines and there is a dangling comma).

  8. bbovenzi commented on Jun 5, 2025

    @bbovenzi
    ContributorAuthor

    They are just static files so I think option 1 makes sense to me. What do you think @pierrejeambrun ?

  9. choo121600 commented on Jun 6, 2025

    @choo121600
    Member

    Thanks for the suggestion @potiuk !
    I totally agree that yaml is more human-friendly and reduces the risk of syntax errors compared to json, especially when translators manually edit the files.

    Currently, the reason we use json is that i18next by default expects translation files in json format on the client side, and loading yaml directly in the browser would require bundling a yaml parser, which would increase the frontend bundle size something we want to avoid for performance reasons.

    To get the best of both worlds, I’m considering the following approach:

    • Store and maintain translation files in yaml format on the backend (making it easier for contributors to edit and review)
    • Serve the translations through an API endpoint that loads yaml files, parses them on the server, and returns json responses
    • Let the frontend continue to load translations as JSON via i18next’s standard HTTP backend without extra yaml parsing in the client

    This way, we keep the translation source files developer and contributor-friendly with yaml, while preserving frontend performance and compatibility with existing i18next tooling.

    Would love to hear your thoughts or concerns on this approach!

  10. potiuk commented on Jun 6, 2025

    @potiuk
    Member

    Yep. 100%. I'd do it exactly the same I figured that Json was because of the client side

  11. pierrejeambrun commented on Jun 10, 2025

    @pierrejeambrun
    Member

    I think you can simply move the translation files to airflow/airflow-core/src/airflow/ui/public. When built, that will not be part of the bundle, and the output dist folder is already served from the backend as a static folder.

    For example the pin_100.png image is already accessible at /static/pin_32.png (dev mode needs to be handled slightly differently, but that already works for other public assets, should be similar for translations)

  12. choo121600 commented on Jun 12, 2025

    @choo121600
    Member

    Thanks @pierrejeambrun ! That's a great point using airflow/airflow-core/src/airflow/ui/public definitely keeps things simple and fits nicely with how other frontend assets are handled.

    If we weren’t aiming to serve translation files from the backend as the issue title suggests I would have gone with that approach too.

    I also think the discussion around improving contributor experience (DX) with YAML, as @potiuk suggested, is very valuable. To achieve both goals, how about we take a two-step approach?

    1. First (For 3.1.0): We implement your simple solution now to fix the urgent bundle size problem and meet the milestone.
    2. Then (As a follow-up): I'll create a new issue to tackle the DX improvements, like YAML processing, for a future release.

    This allows us to meet the 3.1.0 milestone while still planning for long-term enhancements.
    What does everyone think of this plan?

  13. potiuk commented on Jun 12, 2025

    @potiuk
    Member

    Sure. Switching to yaml is just a small improvement, it is not "necessary". And if it makes things easier/less dependencies with serving files directly it can stay like that even.

  14. pierrejeambrun commented on Jun 12, 2025

    @pierrejeambrun
    Member

    Sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:APIarea:UIkind:feature

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions