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:
parent
20a44974d5
commit
b3acfe0331
4 changed files with 27 additions and 4 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "anvil",
|
"name": "anvil",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "anvil",
|
"name": "anvil",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "1.41.2",
|
"@playwright/test": "1.41.2",
|
||||||
"@skeletonlabs/skeleton": "2.8.0",
|
"@skeletonlabs/skeleton": "2.8.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "anvil",
|
"name": "anvil",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|
|
@ -3,10 +3,19 @@ import { init, register } from 'svelte-i18n';
|
||||||
|
|
||||||
const defaultLocale = 'en';
|
const defaultLocale = 'en';
|
||||||
|
|
||||||
register('en', () => import('./locales/en.json'));
|
|
||||||
register('de', () => import('./locales/de.json'));
|
register('de', () => import('./locales/de.json'));
|
||||||
|
register('en', () => import('./locales/en.json'));
|
||||||
|
register('he', () => import('./locales/he.json'));
|
||||||
|
|
||||||
init({
|
init({
|
||||||
fallbackLocale: defaultLocale,
|
fallbackLocale: defaultLocale,
|
||||||
initialLocale: browser ? window.navigator.language : defaultLocale
|
initialLocale: browser ? window.navigator.language : defaultLocale
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function mapLocaleToDir(locale: 'de' | 'en' | 'he'): 'ltr' | 'rtl' {
|
||||||
|
if (['he'].includes(locale)) {
|
||||||
|
return 'rtl';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'ltr';
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,15 @@
|
||||||
// Most of your app wide CSS should be put in this file
|
// Most of your app wide CSS should be put in this file
|
||||||
import '../app.postcss';
|
import '../app.postcss';
|
||||||
import { AppShell, AppBar } from '@skeletonlabs/skeleton';
|
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>
|
</script>
|
||||||
|
|
||||||
<!-- App Shell -->
|
<!-- App Shell -->
|
||||||
|
@ -18,6 +27,11 @@
|
||||||
<strong class="text-xl">Anvil</strong>
|
<strong class="text-xl">Anvil</strong>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<svelte:fragment slot="trail">
|
<svelte:fragment slot="trail">
|
||||||
|
<select bind:value={$locale} class="select">
|
||||||
|
{#each $locales as locale}
|
||||||
|
<option value={locale}>{locale}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
<a
|
<a
|
||||||
class="btn btn-sm variant-ghost-surface"
|
class="btn btn-sm variant-ghost-surface"
|
||||||
href="https://matrix.to/#/#general-forgefed:matrix.batsense.net"
|
href="https://matrix.to/#/#general-forgefed:matrix.batsense.net"
|
||||||
|
|
Loading…
Reference in a new issue