Skip to content

feat: add internationalization (i18n) support#485

Open
Jefsky wants to merge 1 commit intoalibaba:mainfrom
Jefsky:main
Open

feat: add internationalization (i18n) support#485
Jefsky wants to merge 1 commit intoalibaba:mainfrom
Jefsky:main

Conversation

@Jefsky
Copy link
Copy Markdown

@Jefsky Jefsky commented Apr 27, 2026

Summary

This PR implements i18n support for the page-agent UI package as requested in issue #195.

Changes Made:

  1. Created JSON locale files:

      • English translations (base language)
      • Chinese translations
  2. **Refactored **:

    • Now imports from JSON locale files instead of having inline objects
    • TypeScript types are inferred from the English JSON schema
    • Maintains the same TranslationKey and TranslationParams types
  3. **Updated **:

    • Added compiler option
    • Included in the include patterns

Architecture:

The i18n system already existed in the codebase (I18n class with locale support for 'en-US' and 'zh-CN'). This PR simply externalizes the translation data into JSON files for easier maintenance and future translation contributions.

Testing:

  • TypeScript compilation: PASSED
  • Library build: PASSED (

root@1.8.1 build:libs
node scripts/build-libs.js

✔ @page-agent/page-controller

@page-agent/page-controller@1.8.1 build
vite build

(node:62494) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36m📦 Building @page-agent/page-controller�[39m
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 11 modules transformed.
rendering chunks...
�[32m
�[36m[unplugin:dts]�[32m Start generate declaration files...�[39m
computing gzip size...
�[2mdist/lib/�[22m�[36mSimulatorMask-BfJiQVCo.js �[39m�[1m�[2m11.60 kB�[22m�[1m�[22m�[2m │ gzip: 3.23 kB�[22m�[2m │ map: 15.64 kB�[22m
�[2mdist/lib/�[22m�[36mpage-controller.js �[39m�[1m�[2m75.11 kB�[22m�[1m�[22m�[2m │ gzip: 16.09 kB�[22m�[2m │ map: 157.83 kB�[22m
�[32m�[36m[unplugin:dts]�[32m Start bundling declaration files...�[39m
Analysis will use the bundled TypeScript version 6.0.3
�[32m�[36m[unplugin:dts]�[32m Declaration files built in 1891ms.
�[39m
�[32m✓ built in 2.14s�[39m

✔ @page-agent/ui

@page-agent/ui@1.8.1 build
vite build

(node:62516) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36m📦 Building @page-agent/ui�[39m
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 9 modules transformed.
rendering chunks...
�[32m
�[36m[unplugin:dts]�[32m Start generate declaration files...�[39m
computing gzip size...
�[2mdist/lib/�[22m�[36mpage-agent-ui.js �[39m�[1m�[2m37.39 kB�[22m�[1m�[22m�[2m │ gzip: 9.77 kB�[22m�[2m │ map: 37.19 kB�[22m
�[32m�[36m[unplugin:dts]�[32m Start bundling declaration files...�[39m
Analysis will use the bundled TypeScript version 6.0.3
�[32m�[36m[unplugin:dts]�[32m Declaration files built in 1798ms.
�[39m
�[32m✓ built in 1.98s�[39m

✔ @page-agent/llms

@page-agent/llms@1.8.1 build
vite build

(node:62483) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36m📦 Building @page-agent/llms�[39m
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 5 modules transformed.
rendering chunks...
�[32m
�[36m[unplugin:dts]�[32m Start generate declaration files...�[39m
computing gzip size...
�[2mdist/lib/�[22m�[36mpage-agent-llms.js �[39m�[1m�[2m13.77 kB�[22m�[1m�[22m�[2m │ gzip: 3.83 kB�[22m�[2m │ map: 26.20 kB�[22m
�[32m�[36m[unplugin:dts]�[32m Start bundling declaration files...�[39m
Analysis will use the bundled TypeScript version 6.0.3
�[32m�[36m[unplugin:dts]�[32m Declaration files built in 1716ms.
�[39m
�[32m✓ built in 1.80s�[39m

✔ @page-agent/core

@page-agent/core@1.8.1 build
vite build

(node:62517) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 5 modules transformed.
rendering chunks...
�[32m
�[36m[unplugin:dts]�[32m Start generate declaration files...�[39m
computing gzip size...
�[2mdist/esm/�[22m�[36mpage-agent-core.js �[39m�[1m�[2m36.34 kB�[22m�[1m�[22m�[2m │ gzip: 11.10 kB�[22m�[2m │ map: 62.76 kB�[22m
�[32m�[36m[unplugin:dts]�[32m Start bundling declaration files...�[39m
Analysis will use the bundled TypeScript version 6.0.3
�[32m�[36m[unplugin:dts]�[32m Declaration files built in 2308ms.
�[39m
�[32m✓ built in 2.42s�[39m

✔ page-agent

page-agent@1.8.1 build
vite build && npm run build:demo

(node:62515) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 1 modules transformed.
rendering chunks...
�[32m
�[36m[unplugin:dts]�[32m Start generate declaration files...�[39m
computing gzip size...
�[2mdist/esm/�[22m�[36mpage-agent.js �[39m�[1m�[2m0.61 kB�[22m�[1m�[22m�[2m │ gzip: 0.29 kB�[22m�[2m │ map: 1.26 kB�[22m
�[32m�[36m[unplugin:dts]�[32m Start bundling declaration files...�[39m
Analysis will use the bundled TypeScript version 6.0.3
�[32m�[36m[unplugin:dts]�[32m Declaration files built in 2636ms.
�[39m
�[32m✓ built in 2.74s�[39m

page-agent@1.8.1 build:demo
vite build --config vite.iife.config.js

(node:62564) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
(Use node --trace-warnings ... to show where the warning was created)
�[36mvite v7.3.2 �[32mbuilding client environment for production...�[36m�[39m
transforming...
�[32m✓�[39m 114 modules transformed.
rendering chunks...
computing gzip size...
�[2mdist/iife/�[22m�[36mpage-agent.demo.js �[39m�[1m�[2m204.56 kB�[22m�[1m�[22m�[2m │ gzip: 57.26 kB�[22m
�[32m✓ built in 320ms�[39m

✔ All 5 tasks completed )

Benefits:

  • Easier for translators to work with JSON files
  • Translation workflow can be integrated with external tools (Crowdin, Weblate, etc.)
  • Clear separation between code and translations

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 27, 2026

CLA assistant check
All committers have signed the CLA.

@gaomeng1900
Copy link
Copy Markdown
Collaborator

Could you explain the expected benefit of this change?

@Jefsky
Copy link
Copy Markdown
Author

Jefsky commented Apr 29, 2026

The key benefits of this change are:

  1. Separation of concerns — Translation data is decoupled from code, making it easier for translators to work with JSON files without touching the codebase
  2. External tooling integration — JSON files can be fed into translation management systems like Crowdin, Weblate, or GitLok, enabling professional translation workflows
  3. Easier maintenance — Adding or updating translations no longer requires code changes or recompilation
  4. Scalability — New language contributions become straightforward (just add a new JSON file following the existing schema)

The existing i18n infrastructure (I18n class with locale support) was already in place — this PR just externalized the inline translation objects into JSON files.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants