]> git.r.bdr.sh - rbdr/forum/blob - src/components/language_selector/language_selector.svelte
Add components to view topics and posts
[rbdr/forum] / src / components / language_selector / language_selector.svelte
1 <script>
2 import { locale, locales } from 'svelte-i18n';
3 import { getLangNameFromCode } from 'language-name-map';
4
5 $: namedLocales = $locales
6 .map((locale) => ({
7 code: locale,
8 ...getLangNameFromCode(locale)
9 }))
10 .sort((a, b) => a.native - b.native);
11
12 let selected = $locale;
13
14 $: {
15 console.log(`the current locale is ${selected}`);
16 locale.set(selected);
17 }
18 </script>
19
20 <select bind:value={selected}>
21 {#each namedLocales as namedLocale}
22 <option value="{ namedLocale.code }">{ namedLocale.native }</option>
23 {/each}
24 </select>
25
26 <style>
27 </style>
28