parseI18nUrl() — astro Function Reference
Architecture documentation for the parseI18nUrl() function in parse-i18n-url.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD f9ca1800_4769_6512_bae6_7f5ca31bc789["parseI18nUrl()"] d149e289_ad70_d2ac_3ff6_cf2830e28fd6["parse-i18n-url.ts"] f9ca1800_4769_6512_bae6_7f5ca31bc789 -->|defined in| d149e289_ad70_d2ac_3ff6_cf2830e28fd6 style f9ca1800_4769_6512_bae6_7f5ca31bc789 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/integrations/sitemap/src/utils/parse-i18n-url.ts lines 7–42
export function parseI18nUrl(
url: string,
defaultLocale: string,
locales: Record<string, string>,
base: string,
): ParsedI18nUrl | undefined {
if (!url.startsWith(base)) {
return undefined;
}
let s = url.slice(base.length);
// Handle root URL
if (!s || s === '/') {
return { locale: defaultLocale, path: '/' };
}
if (s[0] !== '/') {
s = '/' + s;
}
// Get locale from path, e.g.
// "/en-US/" -> "en-US"
// "/en-US/foo" -> "en-US"
const locale = s.split('/')[1];
if (locale in locales) {
// "/en-US/foo" -> "/foo"
let path = s.slice(1 + locale.length);
if (!path) {
path = '/';
}
return { locale, path };
}
return { locale: defaultLocale, path: s };
}
Domain
Subdomains
Source
Frequently Asked Questions
What does parseI18nUrl() do?
parseI18nUrl() is a function in the astro codebase, defined in packages/integrations/sitemap/src/utils/parse-i18n-url.ts.
Where is parseI18nUrl() defined?
parseI18nUrl() is defined in packages/integrations/sitemap/src/utils/parse-i18n-url.ts at line 7.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free