Skip to content

For v30: Fix base language preferred over regional variant in auto-detection 🌐#3506

Merged
evanpelle merged 1 commit intomainfrom
fix-lang-base-match
Mar 24, 2026
Merged

For v30: Fix base language preferred over regional variant in auto-detection 🌐#3506
evanpelle merged 1 commit intomainfrom
fix-lang-base-match

Conversation

@FloPinguin
Copy link
Copy Markdown
Contributor

Description:

When the browser reports a locale like de-DE, the language selector didn't find an exact match and fell through to candidate matching, where it picked de-CH (Swiss German) over de (German) because longer codes were sorted first.

This adds an early check: if the base language code (e.g. de) is directly supported, return it immediately before scanning regional candidates.

FYI @Aotumuri

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

FloPinguin

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf097fcd-f090-4f9b-8971-d316214fb89e

📥 Commits

Reviewing files that changed from the base of the PR and between 2be8588 and 4b500e0.

📒 Files selected for processing (1)
  • src/client/LangSelector.ts

Walkthrough

The getClosestSupportedLang method now prioritizes immediate matches of language base codes (first two characters) within the supported language set, bypassing the previous candidate filtering and specificity sorting logic for base matches.

Changes

Cohort / File(s) Summary
Language Fallback Resolution
src/client/LangSelector.ts
Modified getClosestSupportedLang to return a language base code immediately upon finding an exact match in the supported set, rather than filtering candidates by prefix and sorting by length. Speeds up fallback resolution for inputs like xx-YY while preserving exact language match behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A language seeker finds its way,
Base codes now match without delay,
No sorting long, just swift and true,
The closest tongue for me and you! 🌍

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: base language is now preferred over regional variants in auto-detection, which aligns with the changeset that modifies language fallback logic.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the problem (longer regional codes picked before base language) and the solution (early base language check).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@github-project-automation github-project-automation bot moved this from Triage to Final Review in OpenFront Release Management Mar 24, 2026
@evanpelle evanpelle merged commit e2d5838 into main Mar 24, 2026
14 checks passed
@evanpelle evanpelle deleted the fix-lang-base-match branch March 24, 2026 19:21
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Mar 24, 2026
evanpelle pushed a commit that referenced this pull request Mar 24, 2026
…tection 🌐 (#3506)

## Description:

When the browser reports a locale like `de-DE`, the language selector
didn't find an exact match and fell through to candidate matching, where
it picked `de-CH` (Swiss German) over `de` (German) because longer codes
were sorted first.

This adds an early check: if the base language code (e.g. `de`) is
directly supported, return it immediately before scanning regional
candidates.

FYI @Aotumuri 

## Please complete the following:

- [X] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [X] I have added relevant tests to the test directory
- [X] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

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

Labels

Bugfix Fixes a bug

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants