40 lines
767 B
Plaintext
40 lines
767 B
Plaintext
---
|
|
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;
|
|
}
|
|
---
|
|
|
|
<ul role="list">
|
|
{
|
|
// create a list of available alternative locale
|
|
availableLocales.map((locale) => (
|
|
<li>
|
|
<a
|
|
href={l(currentRoute as any, {}, locale as any)}
|
|
class="clean-link nice-link"
|
|
>
|
|
{localeName(locale)}
|
|
</a>
|
|
</li>
|
|
))
|
|
}
|
|
</ul>
|