This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add locale preferences to preferences sheet
- Loading branch information
Showing
11 changed files
with
125 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"preferences": "Locale Preferences", | ||
"language": "Language" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/lib/shared/layout/preferences/LocalePreferencesSection.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script lang="ts"> | ||
import Icon from '@iconify/svelte'; | ||
import { parse } from 'bcp-47'; | ||
import * as m from '$lib/shared/i18n/compiled/messages'; | ||
import { availableLanguageTags } from '$lib/shared/i18n/compiled/runtime'; | ||
import { type AvailableLanguageTag, languageTag } from '$lib/shared/i18n/compiled/runtime'; | ||
import { localePreference } from '$lib/shared/i18n/index'; | ||
import { availableThemeModes, availableThemes } from '$lib/shared/theme/options'; | ||
import { ThemeMode, themeMode } from '$lib/shared/theme/preferences'; | ||
import { Label } from '$lib/vgui/components/ui/label'; | ||
import * as Select from '$lib/vgui/components/ui/select'; | ||
import type { SelectOption } from '@melt-ui/svelte'; | ||
const getLanguageName = (locale: string): string => { | ||
return ( | ||
new Intl.DisplayNames([locale], { | ||
type: 'language' | ||
}).of(locale) || locale | ||
); | ||
}; | ||
const getLanguageFlag = (locale: string): string => { | ||
const parsed = parse(locale, { forgiving: true }); | ||
return parsed.region ? `flag:${parsed.region.toLowerCase()}-1x1` : 'tabler:language'; | ||
}; | ||
const handleLanguageSelectedChange = (v: SelectOption<unknown> | undefined) => { | ||
if (v) { | ||
localePreference.set(v.value as AvailableLanguageTag); | ||
} | ||
}; | ||
</script> | ||
|
||
<div class="space-y-4"> | ||
<div class="space-y-2"> | ||
<Label>{m.locale_language()}</Label> | ||
<Select.Root | ||
portal={null} | ||
onSelectedChange={handleLanguageSelectedChange} | ||
selected={{ value: $localePreference, label: getLanguageName(languageTag()) }} | ||
> | ||
<Select.Trigger> | ||
<Select.Value asChild> | ||
<div class="flex gap-x-3"> | ||
<Icon icon={getLanguageFlag(languageTag())} class="h-5 w-5" /> | ||
{getLanguageName(languageTag())} | ||
</div> | ||
</Select.Value> | ||
</Select.Trigger> | ||
<Select.Content> | ||
{#each availableLanguageTags as language} | ||
<Select.Item value={language} label={getLanguageName(language)} class="flex gap-x-3"> | ||
<Icon icon={getLanguageFlag(language)} class="h-5 w-5" /> | ||
{getLanguageName(language)} | ||
</Select.Item> | ||
{/each} | ||
</Select.Content> | ||
<Select.Input name="language" /> | ||
</Select.Root> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script lang="ts"> | ||
import Icon from '@iconify/svelte'; | ||
import * as m from '$lib/shared/i18n/compiled/messages'; | ||
import LocalePreferencesSection from '$lib/shared/layout/preferences/LocalePreferencesSection.svelte'; | ||
import ThemePreferencesSection from '$lib/shared/layout/preferences/ThemePreferencesSection.svelte'; | ||
import { Button } from '$lib/vgui/components/ui/button'; | ||
import * as Sheet from '$lib/vgui/components/ui/sheet'; | ||
export let side: 'right' | 'bottom'; | ||
export let open: boolean; | ||
</script> | ||
|
||
<Sheet.Root bind:open> | ||
<Sheet.Content {side} class="space-y-4"> | ||
<section> | ||
<Sheet.Header> | ||
<Sheet.Title>{m.locale_preferences()}</Sheet.Title> | ||
</Sheet.Header> | ||
|
||
<div class="py-4"> | ||
<LocalePreferencesSection /> | ||
</div> | ||
</section> | ||
|
||
<section> | ||
<Sheet.Header> | ||
<Sheet.Title>{m.theme_preferences()}</Sheet.Title> | ||
</Sheet.Header> | ||
|
||
<div class="py-4"> | ||
<ThemePreferencesSection /> | ||
</div> | ||
</section> | ||
</Sheet.Content> | ||
</Sheet.Root> |
File renamed without changes.