feat: include a language switcher

This also sets the direction of layout. I hope to be able to spot design
implementation failures faster this way.

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
André Jaenisch 2024-02-20 13:50:41 +01:00
parent 20a44974d5
commit b3acfe0331
No known key found for this signature in database
GPG key ID: 5A668E771F1ED854
4 changed files with 27 additions and 4 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "anvil",
"version": "0.0.3",
"version": "0.0.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "anvil",
"version": "0.0.3",
"version": "0.0.4",
"devDependencies": {
"@playwright/test": "1.41.2",
"@skeletonlabs/skeleton": "2.8.0",

View file

@ -1,6 +1,6 @@
{
"name": "anvil",
"version": "0.0.3",
"version": "0.0.4",
"private": true,
"scripts": {
"dev": "vite dev",

View file

@ -3,10 +3,19 @@ import { init, register } from 'svelte-i18n';
const defaultLocale = 'en';
register('en', () => import('./locales/en.json'));
register('de', () => import('./locales/de.json'));
register('en', () => import('./locales/en.json'));
register('he', () => import('./locales/he.json'));
init({
fallbackLocale: defaultLocale,
initialLocale: browser ? window.navigator.language : defaultLocale
});
export function mapLocaleToDir(locale: 'de' | 'en' | 'he'): 'ltr' | 'rtl' {
if (['he'].includes(locale)) {
return 'rtl';
}
return 'ltr';
}

View file

@ -7,6 +7,15 @@
// Most of your app wide CSS should be put in this file
import '../app.postcss';
import { AppShell, AppBar } from '@skeletonlabs/skeleton';
import { locale, locales } from 'svelte-i18n';
import { mapLocaleToDir } from '$lib/i18n';
locale.subscribe((l) => {
if (typeof document !== 'undefined') {
document.dir = mapLocaleToDir(l);
}
});
</script>
<!-- App Shell -->
@ -18,6 +27,11 @@
<strong class="text-xl">Anvil</strong>
</svelte:fragment>
<svelte:fragment slot="trail">
<select bind:value={$locale} class="select">
{#each $locales as locale}
<option value={locale}>{locale}</option>
{/each}
</select>
<a
class="btn btn-sm variant-ghost-surface"
href="https://matrix.to/#/#general-forgefed:matrix.batsense.net"