Skip to content

Add domainLocales to useRouter #26474

@quantizor

Description

@quantizor

Describe the feature you'd like to request

Currently domainLocales is specified as an optional field on the return of useRouter but in looking at the client version of router.ts it actually is never initialized. We would like access to this so we can restrict what languages to present to the user in our language picker based on what domain they are visiting.

Describe the solution you'd like

For example config:

{
  i18n: {
    domains: [
      {
        domain: 'x.com',
        defaultLocale: 'en-US',
        locales: ['en-US', 'es'],
      },
      {
        domain: 'x.in',
        defaultLocale: 'en-IN',
        locales: ['en-IN'],
      },
    ],
    locales: ['en-IN', 'en-US', 'es'],
    defaultLocale: 'en-US',
  },
}

If the user lands on x.com the intent is for router.domainLocales to only have ["en-US", "es"] client-side so we are not showing undesired locales.

Describe alternatives you've considered

The only real alternative is to also maintain this mapping in our src directory and do hostname switching. It works but the types for useRouter imply that this field should be available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions