-
Notifications
You must be signed in to change notification settings - Fork 39
Create Plugin: i18n addition script #2320
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
base: main
Are you sure you want to change the base?
Conversation
- Create additions registry for managing optional feature additions
- Implement additions manager with runAddition, executeAddition
- Add utilities that reuse migration infrastructure (Context, formatFiles, etc.)
- Support for version-agnostic, idempotent additions
- Designed to be extensible for future additions beyond i18n
Fri Oct 17 09:48:24 2025 +0200
add core infrastructure for 'add' command
implement 'add' command with pre-flight checks
implement 'add i18n' script with full automation
packages/create-plugin/src/additions/additions.ts
packages/create-plugin/src/additions/manager.ts
packages/create-plugin/src/additions/utils.ts
d9f7476 to
3154eaa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new create-plugin add i18n command that automates the setup of internationalization (i18n) infrastructure for Grafana plugins. The addition intelligently handles backward compatibility, supporting both Grafana 11.x (with manual resource loading) and Grafana 12.1.0+ (with automatic resource loading). The implementation follows defensive programming practices, making it safe to run multiple times without overwriting existing configurations.
Key changes:
- Adds comprehensive i18n addition script with schema validation using Valibot
- Updates rollup config to support nested script directories with
**/*.tsglob pattern - Bumps default panel template Grafana dependency to 11.5.0
- Includes extensive test coverage across multiple test files
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| rollup.config.ts | Updated glob pattern to support nested addition script folders |
| packages/create-plugin/templates/panel/src/plugin.json | Bumped grafanaDependency from 10.4.0 to 11.5.0 |
| packages/create-plugin/src/codemods/additions/scripts/i18n/utils.ts | React version validation and locale file creation utilities |
| packages/create-plugin/src/codemods/additions/scripts/i18n/utils.test.ts | Unit tests for React version checking |
| packages/create-plugin/src/codemods/additions/scripts/i18n/tooling.ts | Dependency management and ESLint configuration updates |
| packages/create-plugin/src/codemods/additions/scripts/i18n/tooling.test.ts | Unit tests for ESLint config updates |
| packages/create-plugin/src/codemods/additions/scripts/i18n/index.ts | Main addition orchestration with Valibot schema validation |
| packages/create-plugin/src/codemods/additions/scripts/i18n/index.test.ts | Comprehensive integration tests covering multiple scenarios |
| packages/create-plugin/src/codemods/additions/scripts/i18n/config-updates.ts | Docker compose, plugin.json, i18next config, and externals updates |
| packages/create-plugin/src/codemods/additions/scripts/i18n/config-updates.test.ts | Unit tests for config update functions |
| packages/create-plugin/src/codemods/additions/scripts/i18n/code-generation.ts | AST manipulation for module initialization and loadResources file generation |
| packages/create-plugin/src/codemods/additions/scripts/i18n/README.md | Comprehensive documentation with usage examples and troubleshooting |
| packages/create-plugin/src/codemods/additions/additions.ts | Registration of i18n addition in the additions registry |
| packages/create-plugin/src/codemods/AGENTS.md | Updated documentation for agent behavior regarding additions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/create-plugin/src/codemods/additions/scripts/i18n/code-generation.ts
Outdated
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/code-generation.ts
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/tooling.ts
Outdated
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/utils.test.ts
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/code-generation.ts
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/code-generation.ts
Outdated
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/index.test.ts
Show resolved
Hide resolved
packages/create-plugin/src/codemods/additions/scripts/i18n/index.ts
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| // Success message with next steps | ||
| console.log('\n✅ i18n support has been successfully added to your plugin!\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem with these "success messages" that runs at the very end of the i18n script is that things can still fail in the next step when the runner format files, flush changes and install deps.
NX handles this by defining a callback function that is triggered once the changes are made to the filesystem. Would we want to introduce a similar pattern? If so I'll address that in a separate PR.
What this PR does / why we need it:
Adds a new
create-plugin add i18ncommand that sets up internationalization infrastructure for Grafana plugins. This automates the configuration of files, dependencies and settings needed for i18n support, making it easier for plugin developers to add translation capabilities.The addition uses a defensive approach and it therefore safe to run multiple times. It performs early validation to ensure React 18+ and Grafana 11.0.0+ are being used, with clear error messages if requirements aren't met. For Grafana 11.x plugins, it automatically sets up backward compatibility with custom resource loading, while Grafana 12.1.0+ plugins use the simpler automatic resource loading approach.
Example usage:
npx @grafana/create-plugin add i18n --locales=en-US,sv-SE,es-ESWhich issue(s) this PR fixes:
Fixes #[issue-number]
Fixes #2346
Special notes for your reviewer:
📦 Published PR as canary version:
Canary Versions✨ Test out this PR locally via:
npm install @grafana/create-plugin@6.5.0-canary.2320.20268447181.0 # or yarn add @grafana/create-plugin@6.5.0-canary.2320.20268447181.0