i18n init
This commit is contained in:
26
client/src/middleware.ts
Normal file
26
client/src/middleware.ts
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user