Skip to content

Conversation

@sunker
Copy link
Contributor

@sunker sunker commented Oct 17, 2025

  • feat(create-plugin): add core infrastructure for 'add' command
  • feat(create-plugin): implement 'add' command with pre-flight checks
  • feat(create-plugin): implement 'add i18n' script with full automation
  • docs(create-plugin): document new 'add' command and 'add i18n' feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install [email protected]
npm install @grafana/[email protected]
npm install @grafana/[email protected]
# or 
yarn add [email protected]
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]

- 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
- Add new 'add' command to CLI (npx @grafana/create-plugin add <feature>)
- Implement pre-flight checks (git directory, clean working tree, plugin directory)
- Add interactive prompts for i18n locale selection using enquirer
- Support for multiple locale selection with multiselect UI
- Allow custom locale codes to be entered manually
- Register command in CLI entry point and command index
Implements complete i18n setup automation:
- Updates docker-compose.yaml with localizationForPlugins feature toggle
- Updates plugin.json with languages array and grafanaDependency >= 12.1.0
- Creates locale folders and translation files for selected locales
- Adds @grafana/i18n dependency to package.json
- Adds i18next-cli dev dependency and i18n-extract script
- Creates i18next.config.ts with proper extraction configuration
- Updates eslint.config.mjs with i18n linting rules
- Adds i18n imports to module.ts/tsx automatically
- Idempotent: safely runs multiple times without breaking
- Comprehensive test suite with 8 passing tests covering:
  * Idempotency verification
  * Single and multiple locale support
  * Skipping when already configured
  * Handling existing feature toggles
  * Support for both .ts and .tsx modules
  * Version-aware dependency updates
  * Edge cases (missing scripts, etc.)

This automates all manual steps shown in grafana/grafana-plugin-examples#588
- Add comprehensive documentation for the new 'add' command
- Document 'add i18n' usage with interactive prompts
- List all actions performed by the i18n addition
- Provide examples of common locales that can be selected
- Link to plugin internationalization documentation
- Explain the automated setup process
@github-actions
Copy link
Contributor

github-actions bot commented Oct 17, 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 minor Increment the minor version when merged release Create a release when this pr is merged labels Oct 17, 2025
- Add additions scripts to rollup input alongside migrations
- Ensures add-i18n.js is compiled and available in dist/
- Fixes module resolution error when running npx @grafana/create-plugin add i18n
@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Plugins Platform / Grafana Community Oct 17, 2025
…lity

This commit enhances the add i18n command to better support plugins
targeting different Grafana versions:

Key improvements:
1. **Backward compatibility for Grafana 11+**: Automatically detects if a
   plugin targets Grafana < 12.1.0 and applies the appropriate configuration:
   - Sets grafanaDependency to >=11.0.0 (instead of >=12.1.0)
   - Creates loadResources.ts file for manual resource loading
   - Adds conditional loader logic in module initialization
   - Adds semver as a regular dependency (not just dev)
   - Skips docker-compose.yaml feature toggle (not needed for < 12.1.0)

2. **Updated dependency versions**:
   - @grafana/i18n: 12.2.2 (was ^1.0.0)
   - Added semver: ^7.6.0 and @types/semver: ^7.5.0 for version checks

3. **Example translations**: Generated locale JSON files now include
   example translation structure (components and config sections) to help
   users understand the format

4. **Build configuration**: Updated rollup.config.ts to properly bundle
   addition scripts from src/additions/scripts directory

The implementation follows the official Grafana documentation for i18n
support in plugins before Grafana 12.1.0, including:
- loadResources.ts for resource loading
- Conditional loaders based on Grafana version
- Proper import setup for semver and config from @grafana/runtime

Tests updated to cover both backward compatibility mode (Grafana 11+)
and modern mode (Grafana 12.1.0+).
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.

1 participant