Skip to content

Conversation

@sunker
Copy link
Contributor

@sunker sunker commented Nov 24, 2025

What this PR does / why we need it:

Adds a new create-plugin add i18n command 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-ES

Which 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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new minor release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@sunker sunker added release Create a release when this pr is merged minor Increment the minor version when merged labels Nov 24, 2025
@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Plugins Platform / Grafana Community Nov 24, 2025
- 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
@sunker sunker force-pushed the create-plugin/i18n-addition branch from d9f7476 to 3154eaa Compare December 15, 2025 09:38
@sunker sunker self-assigned this Dec 16, 2025
@sunker sunker changed the title (wip) Create Plugin: i18n addition script Create Plugin: i18n addition script Dec 16, 2025
@sunker sunker marked this pull request as ready for review December 16, 2025 12:16
@sunker sunker requested a review from a team as a code owner December 16, 2025 12:16
Copilot AI review requested due to automatic review settings December 16, 2025 12:16
@sunker sunker requested a review from a team as a code owner December 16, 2025 12:16
@sunker sunker requested review from Ukochka, academo, s4kh and xnyo December 16, 2025 12:16
Copy link
Contributor

Copilot AI left a 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 **/*.ts glob 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.

}

// Success message with next steps
console.log('\n✅ i18n support has been successfully added to your plugin!\n');
Copy link
Contributor Author

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.

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

Labels

minor Increment the minor version when merged release Create a release when this pr is merged

Projects

Status: 🔬 In review

Development

Successfully merging this pull request may close these issues.

Feat: Create add cmd script to add i18n support

1 participant