generated from dave/wails-template
Implement localization
This commit is contained in:
26
frontend/src/lib/components/LanguageSwitcher.svelte
Normal file
26
frontend/src/lib/components/LanguageSwitcher.svelte
Normal file
@@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { locale, isLoading } from 'svelte-i18n';
|
||||
import { GetLocale, SetLocale } from '$wails/main/App';
|
||||
|
||||
const languages = [
|
||||
{ code: 'en', name: 'EN' },
|
||||
{ code: 'ru', name: 'RU' }
|
||||
];
|
||||
|
||||
async function setLanguage(lang: string) {
|
||||
$locale = lang;
|
||||
await SetLocale(lang);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex gap-1">
|
||||
{#each languages as lang}
|
||||
<button
|
||||
class="px-3 py-1 rounded-lg transition-colors {$locale === lang.code ? 'bg-blue-500 text-white' : 'bg-gray-800 text-gray-300 hover:bg-gray-700'}"
|
||||
on:click={() => setLanguage(lang.code)}
|
||||
disabled={$isLoading}
|
||||
>
|
||||
{lang.name}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
Reference in New Issue
Block a user