Skip to content
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

added i18n support for plugins #10182

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

added i18n support for plugins #10182

wants to merge 1 commit into from

Conversation

khavinshankar
Copy link
Member

@khavinshankar khavinshankar commented Jan 25, 2025

Proposed Changes

  • Added support for i18n for plugins

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced internationalization (i18n) support with dynamic translation resource loading
    • Improved app configuration with more detailed app name extraction
  • Dependencies

    • Added i18next-resources-to-backend package
    • Updated @types/node to latest version
  • Improvements

    • Refined translation resource handling
    • Added default namespace for translations
    • Implemented more robust URL generation for translation files

@khavinshankar khavinshankar requested a review from a team as a code owner January 25, 2025 11:09
Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

Walkthrough

The pull request introduces enhancements to the internationalization (i18n) configuration and app configuration management. In care.config.ts, a new name property is added to the careApps array, enabling more detailed app representation. The package.json is updated with a new i18next-related dependency and a Node.js type definitions upgrade. The src/i18n.ts file receives significant changes, implementing dynamic translation resource loading based on the application configuration, with improved URL handling and namespace management.

Changes

File Change Summary
care.config.ts Added name property to careApps array by extracting name from app variable
package.json - Added i18next-resources-to-backend@1.2.1 dependency
- Updated @types/node from ^22.9.0 to ^22.10.10
src/i18n.ts - Added toURL() and namespaceToUrl() functions
- Implemented dynamic translation resource loading
- Updated i18n.init() configuration with new namespace and default namespace settings

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant Config as careConfig
    participant I18n as i18n Module
    participant Backend as Translation Backend

    App->>Config: Retrieve careApps
    Config-->>App: Return app configurations
    App->>I18n: Initialize with namespaces
    I18n->>I18n: Generate namespace URLs
    I18n->>Backend: Fetch translations dynamically
    Backend-->>I18n: Return translation resources
Loading

Possibly related PRs

Suggested reviewers

  • shivankacker
  • rithviknishad

Poem

🐰 Translations dance, config takes flight,
Namespaces bloom with digital might.
Rabbits of code, we hop and we sing,
Internationalization's a wonderful thing!
Configs aligned, resources unfurled. 🌍

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

netlify bot commented Jan 25, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit dd280b2
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6794c67b72b03800086eabe1
😎 Deploy Preview https://deploy-preview-10182--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: dd280b2
Status: ✅  Deploy successful!
Preview URL: https://580d9205.care-fe.pages.dev
Branch Preview URL: https://plugs-i18n.care-fe.pages.dev

View logs

Copy link

cypress bot commented Jan 25, 2025

CARE    Run #4408

Run Properties:  status check passed Passed #4408  •  git commit dd280b2c0c: added i18n support for plugins
Project CARE
Branch Review plugs-i18n
Run status status check passed Passed #4408
Run duration 02m 53s
Commit git commit dd280b2c0c: added i18n support for plugins
Committer Khavin Shankar
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5
View all changes introduced in this branch ↗︎

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/i18n.ts (2)

17-27: Consider validating or defaulting empty input
If input is empty or whitespace only, the function returns "https://"—which may fail later. A fallback or validation for an empty string can help avoid such errors.


43-63: Optionally provide a fallback for missing translations
If translation fetch fails, the callback passes an error, causing the i18n load to break. Returning an empty object can keep the UI partially functional rather than halting.

Possible fallback approach:

 .catch((error) => {
   console.error(
     `Failed to load translations for ${language}/${namespace}:`,
     error,
   );
-  callback(error, null);
+  callback(null, {});
 });
care.config.ts (1)

124-124: Safeguard against invalid string patterns
Splitting the string twice may fail if the app name doesn't follow organization/app@branch. Consider a fallback or error handling if a slash is missing.

- name: app.split("@")[0].split("/")[1],
+ const [org, appName] = app.split("@")[0].split("/");
+ name: appName || org,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 131111f and dd280b2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • care.config.ts (1 hunks)
  • package.json (2 hunks)
  • src/i18n.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (6)
src/i18n.ts (4)

1-1: No issues with this import
Essential import for referencing the careConfig.


5-5: No issues with the new dependency import
The resourcesToBackend import is properly integrated and aligns with the i18n enhancement.


66-66: Dynamic namespaces are well implemented
Adding ...careConfig.careApps.map(app => app.name) ensures robust multi-app translation support.


73-73: Default namespace choice looks good
Setting defaultNS to "care_fe" is consistent with your existing codebase.

package.json (2)

103-103: New i18n resource dependency
Good addition for enabling dynamic resource loading.


142-142: Incremental type definition update
Updating @types/node to ^22.10.10 is generally safe.

Comment on lines +29 to +37
const namespaceToUrl = (namespace: string) => {
const careApp = careConfig.careApps.find((app) => app.name === namespace);

if (!careApp) {
return "";
}

return toURL(careApp.branch);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Confirmed: Missing branch handling will cause runtime errors
The code has a critical issue where careApp.branch can be undefined when using GitHub Pages format ("organization/repository"), causing toURL(undefined) to throw runtime errors. This needs to be fixed as it affects the application's stability.

  • In src/i18n.ts: Add null check and fallback for careApp.branch before passing to toURL
  • Consider adding validation for required branch field in care.config.ts
🔗 Analysis chain

Handle potential missing or empty branch field
If careApp.branch is empty or undefined, returning https://undefined could lead to failed translations fetching. Recommend a fallback or an explicit error message.

Please confirm branch is always valid:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Checking if `branch` is guaranteed for all items in careApps
rg 'careApps(\s+)?(:|=)' -A 10

Length of output: 1974


Script:

#!/bin/bash
# Check for REACT_ENABLED_APPS validation and other branch usages
rg "REACT_ENABLED_APPS" -A 5
rg "careApp.*branch" -A 2

Length of output: 2001


Script:

#!/bin/bash
# Check toURL implementation
rg "function toURL|const toURL" -A 5

Length of output: 323

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.

1 participant