File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ interface Props {}
33
44import { useTranslations } from " ../i18n/utils" ;
55import type { Params } from " ../i18n/utils" ;
6+ import { languages } from " ../i18n/ui" ;
67import { Image } from " astro:assets" ;
78import aux from " ../../public/aux.svg" ;
89
@@ -33,6 +34,27 @@ const translation = useTranslations(lang);
3334 >
3435 </li >
3536 <li ><a href =" https://github.com/auxolotl" >GitHub</a ></li >
37+
38+ <select data-lang-selector class =" bg-transparent" >
39+ {
40+ Object .keys (languages ).map ((lang ) => (
41+ <option value = { lang } class = " text-black" >
42+ { languages [lang as keyof typeof languages ]}
43+ </option >
44+ ))
45+ }
46+ </select >
3647 </ul >
3748 </nav >
3849</header >
50+
51+ <script >
52+ import { switchLang } from "../i18n/utils";
53+ import type { languages } from "../i18n/ui";
54+ const select: HTMLSelectElement | null = document.querySelector(
55+ "[data-lang-selector]",
56+ );
57+ select?.addEventListener("change", () => {
58+ switchLang(select.value as keyof typeof languages);
59+ });
60+ </script >
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ export function useTranslations(lang: keyof typeof ui) {
1111 } ;
1212}
1313
14+ export function switchLang ( lang : keyof typeof ui ) {
15+ const parts = location . pathname . split ( "/" ) ;
16+ parts [ 1 ] = lang ;
17+ location . href = parts . join ( "/" ) ;
18+ }
19+
1420export const getStaticPaths = ( async ( ) => {
1521 return Object . keys ( languages ) . map ( ( name ) => ( {
1622 params : { lang : name as keyof typeof languages } ,
You can’t perform that action at this time.
0 commit comments