Skip to content

fix: support lowercase regional locale routes - #209

Open
laaichiu wants to merge 3 commits into
spree:mainfrom
laaichiu:fix-regional-locale-routing
Open

fix: support lowercase regional locale routes#209
laaichiu wants to merge 3 commits into
spree:mainfrom
laaichiu:fix-regional-locale-routing

Conversation

@laaichiu

@laaichiu laaichiu commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Closes #208

Thanks for reporting this. We traced the two behaviors to different causes:

  1. GB / en-GB
    The Market accepted en-GB, but the storefront only had en registered in its locale registry. As a result, the regional route was rejected and could lead to a 404. We now support the lowercase route locale en-gb while reusing the existing messages/en.json bundle. /gb/en-GB is canonicalized to /gb/en-gb.

  2. JP / ja
    The Japan Market is configured with ja, but the storefront currently does not include a Japanese message bundle. Market configuration alone does not make a locale renderable by the storefront, so unsupported ja requests safely redirect to the configured default route /us/en. This is expected behavior.

To serve Japan in Japanese, we need to add and register messages/ja.json. If Japan should use English for now, the Market default locale should be set to en while keeping Japan’s country and currency settings.

Summary by CodeRabbit

  • New Features

    • Added support for UK English routes and language selection.
    • Regional locale values are now recognized case-insensitively and displayed consistently in lowercase route formats.
    • Markets without available languages now show a localized “Language unavailable” option.
  • Bug Fixes

    • Country switching, redirects, cart updates, and root-path localization now preserve regional locales correctly.
    • Unsupported and duplicate languages are filtered from language selection.
    • Language selection and updates are disabled when no supported language is available.

@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@laaichiu is attempting to deploy a commit to the Spree Commerce Team on Vercel.

A member of the Team first needs to authorize it.

@strix-security

strix-security Bot commented Aug 9, 2026

Copy link
Copy Markdown

Strix Security Review

No security issues found.

Updated for 281ff2f.


Reviewed by Strix
Re-run review · Configure security review settings

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a550bf48-a724-417b-9b06-a2d2dbd2c8f5

📥 Commits

Reviewing files that changed from the base of the PR and between 384a187 and 281ff2f.

📒 Files selected for processing (9)
  • messages/de.json
  • messages/en.json
  • messages/es.json
  • messages/fr.json
  • messages/pl.json
  • src/components/layout/RegionPreferences.tsx
  • src/components/layout/__tests__/RegionPreferences.test.tsx
  • src/hooks/__tests__/useCountrySwitch.test.ts
  • src/hooks/useCountrySwitch.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useCountrySwitch.ts

Walkthrough

The change adds canonical regional-locale normalization. Routing, market locale resolution, layout handling, region preferences, country switching, middleware, and tests now use lowercase route locales such as en-gb.

Changes

Regional locale normalization

Layer / File(s) Summary
Locale normalization and market support
src/i18n/normalize.ts, src/i18n/locales.ts, src/i18n/__tests__/*
Adds toRouteLocale, registers en-gb, and validates case-insensitive regional locale resolution and market targets.
Localized redirects and route resolution
src/i18n/routing.ts, src/lib/spree/middleware.test.ts, src/i18n/__tests__/routing.test.ts, src/app/[country]/[locale]/layout.test.tsx
Redirects and route resolution use lowercase regional locales while preserving country and pathname values.
Country selection and locale switching
src/components/layout/RegionPreferences.tsx, src/components/layout/__tests__/RegionPreferences.test.tsx, src/hooks/useCountrySwitch.ts, src/hooks/__tests__/useCountrySwitch.test.ts, messages/*.json
Normalizes locale comparisons, filters unsupported locales, disables unavailable selections, and updates cart, cookies, and navigation targets during country changes.

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

Sequence Diagram(s)

sequenceDiagram
  participant RegionPreferences
  participant useCountrySwitch
  participant Cart
  participant Cookies
  participant Router
  RegionPreferences->>useCountrySwitch: select country with en-GB
  useCountrySwitch->>Cart: update locale to en-gb
  useCountrySwitch->>Cookies: store en-gb
  useCountrySwitch->>Router: navigate to /gb/en-gb/products
Loading

Possibly related PRs

Suggested reviewers: damianlegawiec

Poem

A rabbit hops through /gb/en-gb,
The route is lowercase and easy to see.
Cart and cookie follow the same sign,
Locale and country now align.
“Hop on,” says the rabbit, “the paths are fine!”

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes the GB regional route, but jp/ja remains unsupported and redirects to /us/en instead of resolving the reported Japan locale issue [#208]. Add and register messages/ja.json, or update the issue scope to explicitly accept fallback redirection for unsupported ja locales.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: support for lowercase regional locale routes.
Out of Scope Changes check ✅ Passed The changes support regional locale normalization, routing, cart synchronization, and unavailable-locale handling required by the PR objectives and issue [#208].
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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
Contributor

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 `@src/hooks/useCountrySwitch.ts`:
- Around line 43-51: Update the early-return condition in useCountrySwitch so it
also verifies that the cart locale is the canonical lowercase target locale
before returning true; preserve the update flow for legacy values such as en-GB
so cart, cookies, and navigation persist en-gb. Add a regression test covering
an en-GB cart on the gb/en-gb route.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f01f1c5-f864-4dcf-bdd2-51582f7ba79d

📥 Commits

Reviewing files that changed from the base of the PR and between e1b2cc7 and 384a187.

📒 Files selected for processing (12)
  • src/app/[country]/[locale]/layout.test.tsx
  • src/components/layout/RegionPreferences.tsx
  • src/components/layout/__tests__/RegionPreferences.test.tsx
  • src/hooks/__tests__/useCountrySwitch.test.ts
  • src/hooks/useCountrySwitch.ts
  • src/i18n/__tests__/locales.test.ts
  • src/i18n/__tests__/markets.test.ts
  • src/i18n/__tests__/routing.test.ts
  • src/i18n/locales.ts
  • src/i18n/normalize.ts
  • src/i18n/routing.ts
  • src/lib/spree/middleware.test.ts

Comment thread src/hooks/useCountrySwitch.ts Outdated
@laaichiu
laaichiu marked this pull request as draft August 9, 2026 07:15
@laaichiu
laaichiu marked this pull request as ready for review August 9, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant