Added lang attribute and helper functions
This commit is contained in:
4
src/i18n/ui.ts
Normal file
4
src/i18n/ui.ts
Normal 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
7
src/i18n/utils.ts
Normal 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
|
||||||
|
}
|
||||||
@@ -1,16 +1,21 @@
|
|||||||
---
|
---
|
||||||
|
import { defaultLang, type Language } from '@/i18n/ui';
|
||||||
|
import { getLangFromUrl } from '@/i18n/utils';
|
||||||
import type { Head } from '@/types/Head';
|
import type { Head } from '@/types/Head';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string;
|
title: string
|
||||||
head?: Head
|
head?: Head
|
||||||
|
lang?: Language
|
||||||
}
|
}
|
||||||
|
|
||||||
const { title, head } = Astro.props;
|
const { title, head } = Astro.props;
|
||||||
|
|
||||||
|
const lang = getLangFromUrl(Astro.url) || defaultLang;
|
||||||
---
|
---
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="fr">
|
<html lang={lang}>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="author" content="Alexis Pelé" />
|
<meta name="author" content="Alexis Pelé" />
|
||||||
|
|||||||
Reference in New Issue
Block a user