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

LanguageSwitcher picked the wrong language in two cases:

  • An unsupported/region-qualified language (e.g. browser en-US when the server only offers en) fell back to whichever language was listed first — which could be Arabic, not English.
  • When a region-qualified language matched a supported one only by base language (e.g. en-US vs. supported en-IN), the switcher couldn't tell dialects apart and could highlight the wrong one.

Fixes the fallback to consistently prefer English, and makes exact-dialect matches (e.g. ta-LK vs. ta-IN) take priority over a same-base-language guess.

Approach

  • Added getBaseLanguage (BCP-47 base language, e.g. en-USen) and normalizeLocaleTag (canonical tag form, for exact-dialect comparison) utils in @thunderid/javascript.
  • LanguageSwitcher's auto-fallback effect now compares base languages instead of raw string equality, and explicitly prefers an English entry over the first available language when the current language isn't supported at all.
  • displayLanguage (what's shown as selected) now tries an exact dialect match first, falls back to a base-language match, and only then to the raw code — so a specific dialect isn't silently collapsed to a sibling or to the bare base language when it's actually offered.

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
    • Added locale utilities for normalizing language tags and identifying base languages.
    • Improved language switching for regional locale variants.
    • Language selection now prefers exact matches, then base-language matches, with sensible fallbacks.
    • Exposed the new locale utilities through the JavaScript package entry point.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SajidMannikeri17, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c055b0bc-e83d-4d4a-a550-fe7ac30d502a

📥 Commits

Reviewing files that changed from the base of the PR and between 3b3a1e7 and 5f00abe.

📒 Files selected for processing (3)
  • packages/javascript/src/utils/__tests__/normalizeLocaleTag.test.ts
  • packages/javascript/src/utils/normalizeLocaleTag.ts
  • packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx
📝 Walkthrough

Walkthrough

The JavaScript package adds locale parsing utilities and exports them publicly. The React LanguageSwitcher uses normalized locale and base-language matching for fallback selection, display selection, and change handling.

Changes

Locale language selection

Layer / File(s) Summary
Locale utilities and public exports
packages/javascript/src/utils/getBaseLanguage.ts, packages/javascript/src/utils/normalizeLocaleTag.ts, packages/javascript/src/index.ts
Adds base-language extraction and locale canonicalization utilities with parsing fallbacks. Exports both utilities from the package entry point.
Language switcher locale matching
packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx
Matches configured languages by normalized locale or base language. Uses English or the first configured language for unsupported locales, and wires the resolved option into selection handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LanguageSwitcher
  participant LocaleUtilities
  participant ConfiguredLanguages
  participant BaseLanguageSwitcher
  LanguageSwitcher->>LocaleUtilities: normalize current locale and extract base language
  LocaleUtilities-->>LanguageSwitcher: return locale values
  LanguageSwitcher->>ConfiguredLanguages: resolve exact or base-language match
  ConfiguredLanguages-->>LanguageSwitcher: return selected language
  LanguageSwitcher->>BaseLanguageSwitcher: provide resolved selection
  BaseLanguageSwitcher-->>LanguageSwitcher: apply language change
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the primary change: correcting default language behavior in i18n translation.
Description check ✅ Passed The description explains the problem, approach, affected behavior, and related sections; unchecked testing and documentation items are non-critical omissions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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/javascript/src/utils/normalizeLocaleTag.ts`:
- Around line 35-41: Update normalizeLocaleTag to guarantee consistent
normalization when Intl.Locale is unavailable: either declare an explicit
runtime/browser support requirement in the package metadata, or implement a
deterministic fallback/polyfill path that preserves exact dialect matching. Add
tests covering both the Intl.Locale path and the fallback behavior, including
en-us versus en-US.
🪄 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: e2cd3a76-50e8-46b3-bc8a-72d09edd4eaa

📥 Commits

Reviewing files that changed from the base of the PR and between 17b03f1 and 3b3a1e7.

📒 Files selected for processing (3)
  • packages/javascript/src/index.ts
  • packages/javascript/src/utils/normalizeLocaleTag.ts
  • packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/javascript/src/index.ts
  • packages/react/src/components/presentation/LanguageSwitcher/LanguageSwitcher.tsx

Comment thread packages/javascript/src/utils/normalizeLocaleTag.ts Outdated
Signed-off-by: Sajid Mannikeri <sajid.mannikeri@ad.infosys.com>
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