Skip to content

Fixed Default Language in i18n translation - #58

Open
SajidMannikeri17 wants to merge 1 commit into
thunder-id:mainfrom
Infosys:bug/2314
Open

Fixed Default Language in i18n translation#58
SajidMannikeri17 wants to merge 1 commit into
thunder-id:mainfrom
Infosys:bug/2314

Conversation

@SajidMannikeri17

@SajidMannikeri17 SajidMannikeri17 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Purpose

Approach

Related Issues

  • N/A

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards.
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • New Features

    • Improved language selection to recognize regional locale variants, such as matching en-US with English.
    • Added fallback behavior when a detected language is unsupported, selecting English or the first configured language.
    • Exposed a utility for resolving a locale’s primary language.
  • Bug Fixes

    • Language switcher selections now remain aligned with the configured language options across locale variants.

Signed-off-by: Sajid Mannikeri <sajid.mannikeri@ad.infosys.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds and exports getBaseLanguage. LanguageSwitcher now matches locale options by base language and selects fallback or displayed options accordingly.

Changes

Locale language selection

Layer / File(s) Summary
Base-language utility and public export
packages/javascript/src/utils/getBaseLanguage.ts, packages/javascript/src/index.ts
Adds getBaseLanguage, which uses Intl.Locale with a hyphen-split fallback, and exports it publicly.
Base-language matching in LanguageSwitcher
packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx
Uses base-language matching for unsupported-language fallback, displayed option selection, change handling, and switcher wiring.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: brionmario, senthalan

Sequence Diagram(s)

sequenceDiagram
  participant LanguageSwitcher
  participant getBaseLanguage
  participant ConfiguredLanguages
  LanguageSwitcher->>getBaseLanguage: Resolve detected locale
  getBaseLanguage-->>LanguageSwitcher: Return base language
  LanguageSwitcher->>ConfiguredLanguages: Find matching configured option
  ConfiguredLanguages-->>LanguageSwitcher: Return matching or fallback option
  LanguageSwitcher->>ConfiguredLanguages: Apply selected option on change
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description copies the template but does not explain the purpose or approach, and all checklist items remain unchecked. Describe the problem and implementation, then update the checklist with the completed tests, documentation, and security checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change to default language handling in i18n translations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/javascript/src/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/javascript/src/utils/getBaseLanguage.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

  • 1 others

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx`:
- Around line 122-125: Update handleLanguageChange to compare the selected
language against currentLanguage rather than displayLanguage, ensuring
switchLanguage runs when the displayed fallback differs from the actual locale.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e68216fc-94c0-4944-a48e-6665d33eec36

📥 Commits

Reviewing files that changed from the base of the PR and between 8c1d729 and 17b03f1.

📒 Files selected for processing (4)
  • packages/javascript/src/index.ts
  • packages/javascript/src/utils/getBaseLanguage.ts
  • packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx
  • packages/react/src/contexts/ThunderID/ThunderIDProvider.tsx

Comment on lines 122 to 125
const handleLanguageChange = (language: string): void => {
if (language !== currentLanguage) {
if (language !== displayLanguage) {
switchLanguage(language);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare the selected locale with currentLanguage.

At Line 123, displayLanguage can differ from currentLanguage. For example, with configured locales en-US and en-GB, a current locale of en-AU displays en-US. When the user selects en-US, this condition prevents switchLanguage, so the concrete locale remains en-AU.

Proposed fix
 const handleLanguageChange = (language: string): void => {
-  if (language !== displayLanguage) {
+  if (language !== currentLanguage) {
     switchLanguage(language);
   }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleLanguageChange = (language: string): void => {
if (language !== currentLanguage) {
if (language !== displayLanguage) {
switchLanguage(language);
}
const handleLanguageChange = (language: string): void => {
if (language !== currentLanguage) {
switchLanguage(language);
}
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx`
around lines 122 - 125, Update handleLanguageChange to compare the selected
language against currentLanguage rather than displayLanguage, ensuring
switchLanguage runs when the displayed fallback differs from the actual locale.

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