<script>
	import { locale, locales } from 'svelte-i18n';
	import { getLangNameFromCode } from 'language-name-map';

	$: namedLocales = $locales
	  .map((code) => ({
	    code,
	    ...getLangNameFromCode(code)
	  }))
	  .sort((a, b) => a.native - b.native);

	let selected = $locale;

	$: {
	  locale.set(selected);
	}
</script>

<select bind:value={selected}>
	{#each namedLocales as namedLocale}
		<option value={namedLocale.code}>{namedLocale.native}</option>
	{/each}
</select>

<style>
</style>
