Skip to content

feat: support i18n for plugin-completion - #248

Merged
kazupon merged 2 commits into
mainfrom
fix/i18n-namespaced
Jul 23, 2025
Merged

kazupon merged 2 commits into
mainfrom
fix/i18n-namespaced

Conversation

@kazupon

@kazupon kazupon commented Jul 23, 2025 •

Copy link
Copy Markdown
Owner

Description

Linked Issues

Additional context

Summary by CodeRabbit

  • New Features

    • Added internationalization (i18n) support to the completion plugin, enabling locale-aware command descriptions and completion suggestions.
    • Introduced a new example CLI script demonstrating i18n and completion plugin integration with localized resources.
  • Bug Fixes

    • Improved error handling and logging for resource loading in i18n plugin.
  • Refactor

    • Modularized and enhanced localization and translation key resolution for commands and arguments.
    • Centralized and streamlined resource normalization and loading for i18n.
  • Documentation

    • Updated and clarified documentation and code examples for i18n resources.
  • Tests

    • Expanded and reorganized test coverage for i18n, completion, and localization features, including type-level tests and locale-specific scenarios.
  • Chores

    • Updated dependencies to reflect new i18n plugin integration and improved type safety.

@coderabbitai

coderabbitai Bot commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This set of changes introduces full internationalization (i18n) support to the completion plugin, restructures localization utilities, and refines type definitions for translation keys and handlers. It also adds comprehensive i18n-aware tests, updates dependencies, and improves documentation and resource normalization in the i18n plugin. Several internal APIs and helpers are updated for context-aware localization.

Changes

Files/Paths Change Summary
packages/plugin-completion/src/index.ts, src/types.ts, src/utils.ts Integrated i18n support into the completion plugin, updated handler signatures to include locale, added helpers for locale-aware completion, and extended context creation for i18n.
packages/plugin-completion/examples/i18n.node.ts Added a new CLI example demonstrating i18n and completion integration with localized command and argument descriptions, completion handlers, and resource loading for Japanese and English locales.
packages/plugin-completion/package.json Added @gunshi/plugin-i18n as a peer and dev dependency.
packages/plugin-completion/src/index.test.ts Added and reorganized tests to cover i18n-aware completion scenarios using the new i18n example CLI, including locale-specific completions and edge cases.
packages/plugin-i18n/src/index.ts, src/types.ts, README.md, src/index.test.ts Modularized and improved resource loading and normalization, enhanced key resolution, updated translation interfaces, removed examples from resources, improved error handling, and updated tests for clarity and coverage.
packages/plugin-renderer/src/index.ts, src/types.ts, src/usage.ts Updated to use new localization utilities and key resolution, changed text property to a generic localization function, and made internal adjustments for context-aware localization.
packages/shared/src/localization.ts, src/types.ts, src/utils.ts, src/index.ts Introduced new localization module, refactored and generalized translation key/type utilities, updated key resolution helpers to be context-aware, and changed export sources.
packages/shared/src/localize.ts Deleted in favor of new localization.ts module.
packages/shared/src/localization.test.ts, src/types.test-d.ts, src/utils.test.ts Updated and expanded tests for localization, translation key resolution, and context-aware key helpers, improving type safety and coverage.
packages/gunshi/src/plugin.ts Added export for CommandContextExtension type from ./types.ts.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant CompletionPlugin
    participant I18nPlugin
    participant CommandContext

    User->>CLI: Run CLI with --completion (with locale)
    CLI->>CompletionPlugin: Initialize completion (locale-aware)
    CompletionPlugin->>I18nPlugin: Load i18n resources for commands
    I18nPlugin->>CommandContext: Inject i18n extension/context
    CompletionPlugin->>CompletionPlugin: Localize completion suggestions
    CompletionPlugin->>User: Output locale-specific completions
Loading

Estimated code review effort

5 (~150+ minutes)

Possibly related PRs

  • #161: Introduces new usage rendering and modifies PluginContext and renderer decoration logic, directly overlapping with changes to plugin context and extension handling.
  • #177: Refactors PluginContext and plugin types, affecting CommandContextExtension and plugin typings, which are also modified here.
  • #188: Introduces the i18n plugin and changes to extension handling, overlapping with i18n integration and CommandContextExtension updates in this PR.

Poem

🐇
In fields of code where plugins grow,
I18n breezes now gently blow.
Completions speak in every tongue,
With context keys deftly strung.
Tests and types in harmony dance—
Rabbits rejoice, for CLI’s enhanced!
🌱✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 358cdcd and 2419f97.

⛔ Files ignored due to path filters (2)
  • packages/plugin-completion/src/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (22)
  • packages/gunshi/src/plugin.ts (1 hunks)
  • packages/plugin-completion/examples/i18n.node.ts (1 hunks)
  • packages/plugin-completion/package.json (1 hunks)
  • packages/plugin-completion/src/index.test.ts (2 hunks)
  • packages/plugin-completion/src/index.ts (6 hunks)
  • packages/plugin-completion/src/types.ts (2 hunks)
  • packages/plugin-completion/src/utils.ts (1 hunks)
  • packages/plugin-i18n/README.md (0 hunks)
  • packages/plugin-i18n/src/index.test.ts (7 hunks)
  • packages/plugin-i18n/src/index.ts (6 hunks)
  • packages/plugin-i18n/src/types.ts (2 hunks)
  • packages/plugin-renderer/src/index.ts (1 hunks)
  • packages/plugin-renderer/src/types.ts (2 hunks)
  • packages/plugin-renderer/src/usage.ts (5 hunks)
  • packages/shared/src/index.ts (1 hunks)
  • packages/shared/src/localization.test.ts (3 hunks)
  • packages/shared/src/localization.ts (1 hunks)
  • packages/shared/src/localize.ts (0 hunks)
  • packages/shared/src/types.test-d.ts (1 hunks)
  • packages/shared/src/types.ts (2 hunks)
  • packages/shared/src/utils.test.ts (2 hunks)
  • packages/shared/src/utils.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kazupon kazupon added the feature Includes new features label Jul 23, 2025
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

Deploying gunshi with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2419f97
Status: ✅  Deploy successful!
Preview URL: https://42f0777d.gunshi.pages.dev
Branch Preview URL: https://fix-i18n-namespaced.gunshi.pages.dev

View logs

@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

@gunshi/bone

npm i https://pkg.pr.new/@gunshi/bone@248

@gunshi/definition

npm i https://pkg.pr.new/@gunshi/definition@248

gunshi

npm i https://pkg.pr.new/gunshi@248

@gunshi/plugin

npm i https://pkg.pr.new/@gunshi/plugin@248

@gunshi/plugin-completion

npm i https://pkg.pr.new/@gunshi/plugin-completion@248

@gunshi/plugin-dryrun

npm i https://pkg.pr.new/@gunshi/plugin-dryrun@248

@gunshi/plugin-global

npm i https://pkg.pr.new/@gunshi/plugin-global@248

@gunshi/plugin-i18n

npm i https://pkg.pr.new/@gunshi/plugin-i18n@248

@gunshi/plugin-renderer

npm i https://pkg.pr.new/@gunshi/plugin-renderer@248

@gunshi/resources

npm i https://pkg.pr.new/@gunshi/resources@248

@gunshi/shared

npm i https://pkg.pr.new/@gunshi/shared@248

commit: 2419f97

@kazupon

kazupon commented Jul 23, 2025

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Labels

feature Includes new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant