astro native i18n + i18n utils

This commit is contained in:
nico 2024-12-28 11:52:32 +01:00
parent 99ef7634e3
commit b7ce5b7f20
Signed by: Nicolas
SSH key fingerprint: SHA256:ELi8eDeNLl5PTn64G+o2Kx5+XVDfHF5um2tZigfwWkM
16 changed files with 266 additions and 163 deletions

View file

@ -1,38 +1,12 @@
---
import { l, astroI18n } from "astro-i18n";
// get all the locales available on the website and remove the one currently in use
const availableLocales = astroI18n.langCodes.filter(
(locale) => locale !== astroI18n.langCode
);
// current path
const currentRoute = Astro.url.pathname;
function localeName(locale) {
let localeName = "";
switch (locale) {
case "fr":
localeName = "Français";
break;
case "en":
localeName = "English";
break;
}
return localeName;
}
import { languages } from '../i18n/ui'
---
<ul role="list">
<ul>
{
// create a list of available alternative locale
availableLocales.map((locale) => (
Object.entries(languages).map(([lang, label]) => (
<li>
<a
href={l(currentRoute as any, {}, locale as any)}
class="clean-link nice-link"
>
{localeName(locale)}
</a>
<a href={`/${lang}/`}>{label}</a>
</li>
))
}