Home / File/ parse-i18n-url.ts — astro Source File

parse-i18n-url.ts — astro Source File

Architecture documentation for parse-i18n-url.ts, a typescript file in the astro codebase.

Entity Profile

Relationship Graph

Source Code

interface ParsedI18nUrl {
	locale: string;
	path: string;
}

// NOTE: The parameters have been schema-validated with Zod
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

Functions

Frequently Asked Questions

What does parse-i18n-url.ts do?
parse-i18n-url.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in parse-i18n-url.ts?
parse-i18n-url.ts defines 1 function(s): parseI18nUrl.
Where is parse-i18n-url.ts in the architecture?
parse-i18n-url.ts is located at packages/integrations/sitemap/src/utils/parse-i18n-url.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/integrations/sitemap/src/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free