Added lang attribute and helper functions

This commit is contained in:
Alexis
2025-03-20 11:31:43 +01:00
parent 1d15272cf8
commit e70841e7b4
3 changed files with 18 additions and 2 deletions

4
src/i18n/ui.ts Normal file
View File

@@ -0,0 +1,4 @@
export const availableLangs = ['en', 'fr'] as const;
export type Language = typeof availableLangs[number];
export const defaultLang: Language = 'fr';

7
src/i18n/utils.ts Normal file
View File

@@ -0,0 +1,7 @@
import { defaultLang, availableLangs, type Language } from './ui';
export function getLangFromUrl(url: URL): Language {
const [, lang] = url.pathname.split('/');
if (availableLangs.includes(lang as Language)) return lang as Language;
return defaultLang
}