astro native i18n + i18n utils
This commit is contained in:
parent
99ef7634e3
commit
b7ce5b7f20
16 changed files with 266 additions and 163 deletions
|
@ -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>
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue