computeCurrentLocale() — astro Function Reference
Architecture documentation for the computeCurrentLocale() function in utils.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD de6dcb0c_8757_883f_cf09_eb13bfa3f1af["computeCurrentLocale()"] 7b0bb4ed_570d_ff47_83a8_9e0495974e66["utils.ts"] de6dcb0c_8757_883f_cf09_eb13bfa3f1af -->|defined in| 7b0bb4ed_570d_ff47_83a8_9e0495974e66 style de6dcb0c_8757_883f_cf09_eb13bfa3f1af fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/i18n/utils.ts lines 146–189
export function computeCurrentLocale(
pathname: string,
locales: Locales,
defaultLocale: string,
): string | undefined {
// pages that use a locale param ([locale].astro or [locale]/index.astro)
// and getStaticPaths make [locale].html the pathname during SSG
// which will not match a configured locale without removing .html
// as we do in normalizeThePath
for (const segment of pathname.split('/').map(normalizeThePath)) {
for (const locale of locales) {
if (typeof locale === 'string') {
// we skip ta locale that isn't present in the current segment
if (!segment.includes(locale)) continue;
if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
return locale;
}
} else {
if (locale.path === segment) {
return locale.codes.at(0);
} else {
for (const code of locale.codes) {
if (normalizeTheLocale(code) === normalizeTheLocale(segment)) {
return code;
}
}
}
}
}
}
// If we didn't exit, it's probably because we don't have any code/locale in the URL.
// We use the default locale.
for (const locale of locales) {
if (typeof locale === 'string') {
if (locale === defaultLocale) {
return locale;
}
} else {
if (locale.path === defaultLocale) {
return locale.codes.at(0);
}
}
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does computeCurrentLocale() do?
computeCurrentLocale() is a function in the astro codebase, defined in packages/astro/src/i18n/utils.ts.
Where is computeCurrentLocale() defined?
computeCurrentLocale() is defined in packages/astro/src/i18n/utils.ts at line 146.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free