/** * The locale from the first URL segment (`/en/...` → `en`), or `defaultLocale` * when the segment isn't one of `locales` (single-locale site, unknown prefix). */ export function localeFromPath(pathname: string, locales: readonly string[], defaultLocale: string): string { const segment = pathname.split('/').filter(Boolean)[0] ?? '' return locales.includes(segment) ? segment : defaultLocale }