Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling for domain to locale mapping (#17771)
Follow-up to #17370 this adds mapping of locales to domains and handles default locales for specific domains also allowing specifying which locales can be visited for each domain. This PR also updates to output all statically generated pages under the locale prefix to make it easier to locate/lookup and to not redirect to the default locale prefixed path when no `accept-language` header is provided.
- Loading branch information
Showing
11 changed files
with
310 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/next/next-server/lib/i18n/detect-domain-locales.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IncomingMessage } from 'http' | ||
|
||
export function detectDomainLocales( | ||
req: IncomingMessage, | ||
domainItems: | ||
| Array<{ | ||
domain: string | ||
locales: string[] | ||
defaultLocale: string | ||
}> | ||
| undefined, | ||
locales: string[], | ||
defaultLocale: string | ||
) { | ||
let curDefaultLocale = defaultLocale | ||
let curLocales = locales | ||
|
||
const { host } = req.headers | ||
|
||
if (host && domainItems) { | ||
// remove port from host and remove port if present | ||
const hostname = host.split(':')[0].toLowerCase() | ||
|
||
for (const item of domainItems) { | ||
if (hostname === item.domain.toLowerCase()) { | ||
curDefaultLocale = item.defaultLocale | ||
curLocales = item.locales | ||
break | ||
} | ||
} | ||
} | ||
|
||
return { | ||
defaultLocale: curDefaultLocale, | ||
locales: curLocales, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.