Skip to content

Commit

Permalink
Simplify language selector implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Sep 3, 2024
1 parent 69b351f commit a941255
Showing 1 changed file with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,31 @@
let languages: string[] = Object.keys(i18n);
type DropdownItem = {
value: string;
label: string;
};
function prepLocale(locale: string) {
return {
value: locale,
label: localeName(locale),
};
}
let dropdownItemData = languages.map(prepLocale);
function localeName(locale: string) {
if (!locale) return 'N/A';
return new Intl.DisplayNames([locale], { type: 'language' }).of(locale) ?? `Error:${locale}`;
}
async function languageSelectChanged(selection: CustomEvent<DropdownItem>) {
$language = selection.detail.value;
}
</script>

<!-- TODO the formatting on this is totally botched, isn't going vertical, is starting open? -->
<Select
name="languageCombobox"
class="w-full h-15"
class="w-full"
buttonClass="bg-surface-200-700-token px-4 text-sm"
itemActiveClass="!bg-surface-300/20"
itemClass="bg-surface-50-900-token"
items={dropdownItemData}
items={languages}
menuClass="bg-surface-50-900-token"

value={prepLocale($language) ?? 'UNSET'}
on:change={languageSelectChanged}
bind:value={$language}
>
<svelte:fragment slot="item" let:item>
<span>{item.label}</span>
<span>{localeName(item)}</span>
</svelte:fragment>
<!-- TODO: dynamic flags
<svelte:fragment slot="itemTrail" let:item>
<span slot="lead" class="h-5 w-5 block">
{localeFlag(item.value)}
</span>
</svelte:fragment>
-->
<svelte:fragment slot="itemTrail" let:item>
<span slot="lead" class="h-5 w-5 block">
{localeFlag(item.value)}
</span>
</svelte:fragment>
-->
</Select>

0 comments on commit a941255

Please sign in to comment.