MCPcopy
hub / github.com/vercel/next.js / detectDomainLocale

Function detectDomainLocale

packages/next-routing/src/i18n.ts:22–48  ·  view source on GitHub ↗
(
  domains: I18nDomain[] | undefined,
  hostname: string | undefined,
  detectedLocale?: string
)

Source from the content-addressed store, hash-verified

20 * Detects the domain locale based on hostname or detected locale
21 */
22export function detectDomainLocale(
23 domains: I18nDomain[] | undefined,
24 hostname: string | undefined,
25 detectedLocale?: string
26): I18nDomain | undefined {
27 if (!domains) return undefined
28
29 const normalizedHostname = hostname?.toLowerCase()
30 const normalizedLocale = detectedLocale?.toLowerCase()
31
32 for (const domain of domains) {
33 // Remove port if present
34 const domainHostname = domain.domain.split(':', 1)[0].toLowerCase()
35
36 if (
37 normalizedHostname === domainHostname ||
38 normalizedLocale === domain.defaultLocale.toLowerCase() ||
39 domain.locales?.some(
40 (locale) => locale.toLowerCase() === normalizedLocale
41 )
42 ) {
43 return domain
44 }
45 }
46
47 return undefined
48}
49
50/**
51 * Normalizes a pathname by removing the locale prefix if present

Callers 3

resolveRoutesFunction · 0.90
i18n.test.tsFile · 0.90
detectLocaleFunction · 0.70

Calls 3

toLowerCaseMethod · 0.80
splitMethod · 0.80
someMethod · 0.80

Tested by

no test coverage detected