forked from open-webui/open-webui
-
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.
- Loading branch information
1 parent
f205e95
commit cb6e09b
Showing
6 changed files
with
110 additions
and
28 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,60 @@ | ||
<script lang="ts"> | ||
// Imports | ||
import i18n, { getLanguages } from '$lib/i18n'; | ||
import { locale } from '$lib/stores'; | ||
import { onMount } from 'svelte'; | ||
import GlobeAlt from '../icons/GlobeAlt.svelte'; | ||
export let isLightMode = false; | ||
export let isInHorizontalNavbar = false; | ||
let opened = false; | ||
const changeLanguage = (code: string) => { | ||
$i18n.changeLanguage(code); | ||
$locale = code; | ||
}; | ||
const toggleDropdown = (e: Event) => { | ||
opened = !opened; | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
}; | ||
onMount(() => { | ||
window.onclick = () => { | ||
if (opened) opened = false; | ||
}; | ||
}); | ||
</script> | ||
|
||
<div | ||
class="group relative flex flex-col text-gray-900 z-20 {isLightMode ? '' : 'dark:text-gray-100'}" | ||
> | ||
{#await getLanguages() then languages} | ||
<button class="text-left text-sm pl-2 flex items-center space-x-1" on:click={toggleDropdown}> | ||
<GlobeAlt /> | ||
<span class={isInHorizontalNavbar ? 'max-sm:hidden' : ''}> | ||
{(languages.find((lang) => lang.code === $i18n.language) || { title: 'Unknown' }).title} | ||
</span> | ||
</button> | ||
<!-- Improve hitbox size --> | ||
<button class="absolute top-full h-2 w-full" on:click={toggleDropdown}></button> | ||
<div | ||
class="absolute top-full mt-2 h-96 w-32 sm:w-56 overflow-y-auto flex-col items-start space-y-2 text-xs bg-white px-4 py-3 border rounded-lg | ||
{isLightMode ? '' : 'dark:bg-gray-800 dark:border-gray-700'} | ||
{opened ? '' : 'hidden group-hover:flex'} " | ||
> | ||
{#each languages as lang} | ||
<button | ||
class="hover:bg-gray-100 w-full text-left p-1 rounded | ||
{isLightMode ? '' : 'dark:hover:bg-gray-700'}" | ||
on:click={() => { | ||
changeLanguage(lang.code); | ||
}} | ||
> | ||
{lang.title} | ||
</button> | ||
{/each} | ||
</div> | ||
{/await} | ||
</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
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 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