i18n init

This commit is contained in:
2025-06-22 07:24:36 +02:00
parent 0dcc1323bd
commit 7eb3a08b20
11 changed files with 627 additions and 50 deletions

26
client/src/middleware.ts Normal file
View File

@@ -0,0 +1,26 @@
import { defineMiddleware } from 'astro:middleware';
import { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE, isSupportedLanguage } from './lib/i18n';
export const onRequest = defineMiddleware(async (context, next) => {
const { pathname } = context.url;
// Skip middleware for static assets
if (pathname.startsWith('/_astro/') || pathname.startsWith('/assets/') || pathname.includes('.')) {
return next();
}
const pathSegments = pathname.split('/').filter(Boolean);
const firstSegment = pathSegments[0];
// If the first segment is a supported language, continue
if (isSupportedLanguage(firstSegment)) {
return next();
}
// If no language prefix, it's Spanish (default) - continue
if (pathname === '/' || !isSupportedLanguage(firstSegment)) {
return next();
}
return next();
});