Skip to content

feat: Handle i18n config from subdomain locales strategy - #3143

Merged
lariciamota merged 4 commits into
feat/multilanguagefrom
feat/domains-locale-strategy
Dec 10, 2025
Merged

lariciamota merged 4 commits into
feat/multilanguagefrom
feat/domains-locale-strategy

Conversation

@lariciamota

@lariciamota lariciamota commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Update the i18n next config to handle subdomain locales strategy.

How it works?

The function buildI18nDomains adds the binding URLs domains in the domains array (i18n next config) if there is no path in the URL.

How to test it?

Test that the path strategy continues working by accessing the locales paths, like /pt-BR.
To test the domains strategy I configured some routing test domains in /etc/hosts, to do that you can follow these steps:

  • In the terminal run sudo vi /etc/hosts
  • Then edit to add the following config:
127.0.0.1  brandless.fast.store.com.br
127.0.0.1  canada.brandless.fast.store
127.0.0.1  brandless.fast.store.com
127.0.0.1  brandless.fast.store
  • Save it and you'll have something like:
Screenshot 2025-12-04 at 18 21 45

Then, run the core and you can test paths and subdomains strategies freely.

Path Subdomain
path - pt-BR domain -  com br
path - it-IT domain - canada
path - en-CA domain -  com
path - en-US

Starters Deploy Preview

References

@lariciamota lariciamota self-assigned this Dec 4, 2025
@codesandbox-ci

codesandbox-ci Bot commented Dec 4, 2025 •

Copy link
Copy Markdown

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.

@lariciamota
lariciamota marked this pull request as ready for review December 4, 2025 21:23
@lariciamota
lariciamota requested a review from a team as a code owner December 4, 2025 21:23
@lariciamota
lariciamota requested review from hellofanny and renatamottam and removed request for a team December 4, 2025 21:23
Comment thread packages/core/scripts/i18n.js Resolved
Comment thread packages/core/scripts/i18n.js Resolved
Comment thread packages/core/i18n.js Resolved
@hellofanny
hellofanny requested review from lemagnetic and ommeirelles and removed request for renatamottam December 9, 2025 16:35

@hellofanny hellofanny 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.

LGTM!

image

I'm not 100% sure about the duplicated domain scenario, but we still need to handle it if it happens. I was thinking that, in this kind of situation, we could check the isDefault property to decide which one should take priority instead of just picking the first one that appears. WDYT?

@lariciamota

Copy link
Copy Markdown
Contributor Author

I was thinking that, in this kind of situation, we could check the isDefault property to decide which one should take priority instead of just picking the first one that appears. WDYT?

AFAIK, the isDefault is for 1 binding per account, so we couldn't use it for that, since it's not 1 default per domain

@lariciamota
lariciamota merged commit c1ec154 into feat/multilanguage Dec 10, 2025
@lariciamota
lariciamota deleted the feat/domains-locale-strategy branch December 10, 2025 17:46
lariciamota added a commit that referenced this pull request Dec 24, 2025
## What's the purpose of this pull request?

Implements a locale/hostname validation system that ensures URLs match
the correct locale configuration based on the hostname. The feature
prevents invalid locale/hostname combinations and returns appropriate
404 responses when configurations don't match.

We want to support multiple locales and they can be configured with
different URL structures:
- **Subdomain bindings**: A hostname dedicated to a locale (e.g.,
`canada.brandless.fast.store` → `fr-CA`)
- **Path-based bindings**: A hostname that serves multiple locales via
paths (e.g., `brandless.fast.store/en-US`, `brandless.fast.store/it-IT`)

Without validation, users could access invalid combinations like:
- `brandless.fast.store/fr-CA/products` → should be 404, as `fr-CA` is
only bound to `canada.brandless.fast.store`
- `canada.brandless.fast.store/en-US/products` → should be 404, as
`en-US` is not bound to this hostname

## How it works?

### SSR & Client-Side Validation

This implementation handles both Server-Side Rendered (SSR) and Static
Site Generated (SSG) pages:

#### SSR Pages (e.g., `/pvt/account/*`)
- **When**: Page uses `getServerSideProps`
- **Where**: Server-side before rendering
- **How**: `withLocaleValidationSSR` HOC wraps `getServerSideProps`
- **Result**: Returns `notFound: true` → Next.js serves 404 page
- **Benefit**: User never sees the invalid page, better SEO

#### SSG Pages (e.g., PLPs, PDPs)
- **When**: Page uses `getStaticProps` (pre-generated at build time)
- **Where**: Client-side after hydration
- **How**: `useEffect` in `_app.tsx` validates after mount
- **Result**: Redirects to `/404` with original path in query string
- **Trade-off**: Page loads before redirect, but SSG pages remain fast

ps.: The same solution from SSR doesn't work on SSG because we don't
have access to hostname on `getStaticProps`.
ps2.: Middleware would work for this use case, but we decided to not use
it to be cost efficient.

#### Validation logic
1. **Localhost bypass**: Allows all locales on `localhost` and
`127.0.0.1` for development tests
2. **Binding check**: Verifies if the locale has a binding for the
hostname
   - Checks all bindings for the given locale
   - Matches if `binding.url` hostname equals the request hostname

## How to test it?
Configure your `etc/hosts` like explained in the previous
[PR](#3143), then test navigating
through the store and changing domains/paths.
In the discovery.config.default, put `enableFaststoreMyAccount` as
`true` to test the `/pvt/account` pages.
### Example Scenarios (based on mock)

#### Valid Combinations ✅
| URL | Type | Result |
| -------------------------------------------- | ---------------- |
------- |
| `brandless.fast.store:3000/pt-BR/apparel` | Path-based | ✅ Valid |
| `brandless.fast.store.com.br:3000/pt-BR` | Subdomain | ✅ Valid |
| `canada.brandless.fast.store:3000/fr-CA` | Subdomain | ✅ Valid |
| `brandless.fast.store:3000/en-US/pvt/account` | Path-based (SSR) | ✅
Valid |

#### Invalid Combinations ❌
| URL | Why Invalid | Result |
| ----------------------------------------------- |
------------------------------------ | -------------- |
| `brandless.fast.store:3000/fr-CA` | fr-CA only bound to canada
subdomain | ❌ 404 (Client) |
| `canada.brandless.fast.store:3000/en-US/apparel` | en-US not bound to
canada subdomain | ❌ 404 (Client) |
| `brandless.fast.store.com:3000/pt-BR/apparel` | pt-BR not bound to
.com | ❌ 404 (Client) |
| `canada.brandless.fast.store:3000/pt-BR/pvt/account` | pt-BR not bound
to canada | ❌ 404 (SSR) |

## References

- [Jira task](https://vtex-dev.atlassian.net/browse/SFS-2990)
- Slack threads
([1](https://vtex.slack.com/archives/C09CZGYTXEE/p1764883650666369),
[2](https://vtex.slack.com/archives/C09CZGYTXEE/p1765564641414739))
lemagnetic added a commit that referenced this pull request Mar 5, 2026
## What's the purpose of this pull request?

Removing hardcoded labels:
- #3099
- #3102 
- #3107 
- #3104 
- #3103 
- #3125
- #3131
- #3116
- #3142
- #3192

Setting Up locales
- #3141
- #3143
- #3147
- #3156
- #3162
- #3145
- #3164
- #3169
- #3171
- #3176
- #3180
- #3169
 custom path
- #3185
- #3162
- #3156
- #3170

Components
- #3093
- #3175

Fetching content 

- #3165

Others
- #3176
- #3171
- #3181
- #3189
- #3205


## How to test locally?
- Run `pnpm I` (install all the new dependencies and needed packages)
- If you want to try localization feature, go
to`/discovery.config.default.js`:
Enable localization:
```
localization: {
  enabled: true
}
```
- Run `node packages/cli/bin/run.js generate-i18n ./packages/core` to
fetch the bindings

If the contentSource is not set to content platform yet, you will see a
message to update to it.
>   contentSource: {
>     type: 'CP',
>   },

⚠️ Note: Ensure the url is set to localhost for local testing. These
locale bindings are generated in `discovery.config` after running the
generate-i18n command.

```diff
localization: {
  enabled: true,
  defaultLocale: 'en-US',
   regions: {...},
    locales: {
      'pt-BR': {
           ...
        bindings: [
          {
            currencyCode: 'BRL',
-           url: 'https://brandless.fast.store/pt-BR',
+           url: 'http://localhost:3000/pt-BR',
            salesChannel: '2',
            isDefault: true,
            locales: [
              {
                code: 'pt-BR',
                isDefault: true,
              },
            ],
          },
        ],
      },
      'it-IT': {
        ...
        bindings: [
          {
            currencyCode: 'EUR',
-           url: 'https://brandless.fast.store/it-IT',
+           url: 'http://localhost:3000/it-IT',
            salesChannel: '3',
            isDefault: true,
            locales: [
              {
                code: 'it-IT',
                isDefault: true,
              },
            ],
          },
          {
            currencyCode: 'EUR',
-           url: 'https://brandless.fast.store/europe/it',
+           url: 'http://localhost:3000/europe/it',
            salesChannel: '3',
            isDefault: false,
            locales: [
              {
                code: 'it-IT',
                isDefault: true,
              },
            ],
          },
        ],
      },
      'en-US': {
        code: 'en-US',
        name: 'English',
        languageCode: 'en',
        languageName: 'English',
        script: 'Latn',
        textDirection: 'ltr',
        regionCode: 'US',
        bindings: [
          {
            currencyCode: 'USD',
-           url: 'https://brandless.fast.store',
+           url: 'http://localhost:3000,
            salesChannel: '1',
            isDefault: true,
            locales: [
              {
                code: 'en-US',
                isDefault: true,
              },
            ],
          },
        ],
      },
    ...
}
```

- Go to /packages/core and run `npmn dev`

---------

Co-authored-by: Larícia Mota <[email protected]>
Co-authored-by: Leandro Rodrigues <[email protected]>
Co-authored-by: Otavio Moreira Meirelles <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.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.

2 participants