Repository navigation
fix: Display native language name instead of English - #3218
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughRefactors locale display name handling in the binding selector: adds a helper to capitalize native locale names and switches disambiguation and label construction to use Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/core/src/sdk/localization/bindingSelector.ts (1)
6-9:capitalizeFirst:str.charAt(0)is not Unicode-safe for astral-plane characters.
charAt+sliceoperate on UTF-16 code units. For a locale whose native name starts with a character outside the BMP (an astral-plane codepoint represented as a surrogate pair), the first surrogate would be uppercased in isolation and the second code unit detached, producing a garbled string. For all practical language names today this never triggers, but it's trivial to make it future-proof:♻️ Spread-based Unicode-safe alternative
function capitalizeFirst(str: string): string { if (!str) return str - return str.charAt(0).toUpperCase() + str.slice(1) + const [first, ...rest] = [...str] + return first.toUpperCase() + rest.join('') }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/sdk/localization/bindingSelector.ts` around lines 6 - 9, The capitalizeFirst function is not Unicode-safe because charAt(0)/slice operate on UTF-16 code units; update capitalizeFirst to operate on Unicode code points by converting the string into an array of grapheme/codepoint elements (e.g., Array.from or spread [...str]), return early on empty input, uppercase the first element with toUpperCase(), then rejoin the remainder with join('') to produce a correct Unicode-safe result; reference the existing function name capitalizeFirst to locate and replace the implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/sdk/localization/bindingSelector.ts`:
- Around line 21-35: The tests fail because buildLanguageOptions now returns
native language names (capitalizeFirst(locale.name)) with region disambiguation;
update the assertions in useBindingSelector.test.tsx to match the native names
produced by buildLanguageOptions—change the expectations for languages['pt-BR']
and languages['pt-PT'] to "Português (BR)" and "Português (PT)" respectively,
and change languages['fr-FR'] to "Français" so the test matches the new output
format.
---
Nitpick comments:
In `@packages/core/src/sdk/localization/bindingSelector.ts`:
- Around line 6-9: The capitalizeFirst function is not Unicode-safe because
charAt(0)/slice operate on UTF-16 code units; update capitalizeFirst to operate
on Unicode code points by converting the string into an array of
grapheme/codepoint elements (e.g., Array.from or spread [...str]), return early
on empty input, uppercase the first element with toUpperCase(), then rejoin the
remainder with join('') to produce a correct Unicode-safe result; reference the
existing function name capitalizeFirst to locate and replace the implementation.
What's the purpose of this pull request?
Uses
nameinstead oflanguageNameto display the language's native name.name– native language label: "português", "italiano", "English", "français"languageName– English label: "Portuguese", "Italian", "English", "French"How to test it?
References
https://vtex.slack.com/archives/C09CZGYTXEE/p1771515982049669
Summary by CodeRabbit