]> git.r.bdr.sh - rbdr/forum/blob - src/lib/components/language_selector/language_selector.svelte
Use tailwind, reference types
[rbdr/forum] / src / lib / components / language_selector / language_selector.svelte
1 <script lang="ts">
2 import { locale, locales } from 'svelte-i18n';
3 import { getLangNameFromCode } from 'language-name-map';
4
5 $: namedLocales = $locales
6 .map((code) => ({
7 code,
8 ...getLangNameFromCode(code)
9 }))
10 .sort((a, b) => {
11 if (a.native > b.native) {
12 return 1;
13 }
14
15 if (a.native < b.native) {
16 return -1;
17 }
18
19 return 0;
20 });
21
22 let selected = $locale;
23
24 $: {
25 locale.set(selected);
26 }
27 </script>
28
29 <select bind:value={selected}>
30 {#each namedLocales as namedLocale}
31 <option value={namedLocale.code}>{namedLocale.native}</option>
32 {/each}
33 </select>
34
35 <style>
36 </style>