mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +00:00
fix(web): language setting (#10024)
This commit is contained in:
parent
9ac2ac2fcb
commit
def5f59242
4 changed files with 20 additions and 19 deletions
|
@ -2,7 +2,7 @@
|
||||||
import type { ComboBoxOption } from '$lib/components/shared-components/combobox.svelte';
|
import type { ComboBoxOption } from '$lib/components/shared-components/combobox.svelte';
|
||||||
import SettingCombobox from '$lib/components/shared-components/settings/setting-combobox.svelte';
|
import SettingCombobox from '$lib/components/shared-components/settings/setting-combobox.svelte';
|
||||||
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
|
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
|
||||||
import { fallbackLang, fallbackLocale, langs, locales } from '$lib/constants';
|
import { defaultLang, fallbackLocale, langs, locales } from '$lib/constants';
|
||||||
import {
|
import {
|
||||||
alwaysLoadOriginalFile,
|
alwaysLoadOriginalFile,
|
||||||
colorTheme,
|
colorTheme,
|
||||||
|
@ -16,8 +16,7 @@
|
||||||
import { findLocale } from '$lib/utils';
|
import { findLocale } from '$lib/utils';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { t, locale as i18nLocale, init } from 'svelte-i18n';
|
import { t, init } from 'svelte-i18n';
|
||||||
import { get } from 'svelte/store';
|
|
||||||
|
|
||||||
let time = new Date();
|
let time = new Date();
|
||||||
|
|
||||||
|
@ -65,18 +64,20 @@
|
||||||
$locale = $locale ? undefined : fallbackLocale.code;
|
$locale = $locale ? undefined : fallbackLocale.code;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const langOptions = langs.map((lang) => ({ label: lang.name, value: lang.code }));
|
||||||
|
const defaultLangOption = { label: defaultLang.name, value: defaultLang.code };
|
||||||
|
|
||||||
const handleLanguageChange = async (newLang: string | undefined) => {
|
const handleLanguageChange = async (newLang: string | undefined) => {
|
||||||
newLang = newLang || fallbackLang;
|
if (newLang) {
|
||||||
$lang = newLang;
|
$lang = newLang;
|
||||||
|
|
||||||
const previousLang = get(i18nLocale);
|
if (newLang === 'dev') {
|
||||||
|
// Reload required, because fallbackLocale cannot be cleared.
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
if (newLang === 'dev') {
|
await init({ fallbackLocale: defaultLang.code, initialLocale: newLang });
|
||||||
await init({ fallbackLocale: 'dev', initialLocale: 'dev' });
|
|
||||||
} else if (previousLang == 'dev' && newLang !== 'dev') {
|
|
||||||
await init({ fallbackLocale: 'en-US', initialLocale: newLang });
|
|
||||||
}
|
}
|
||||||
$i18nLocale = newLang;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLocaleChange = (newLocale: string | undefined) => {
|
const handleLocaleChange = (newLocale: string | undefined) => {
|
||||||
|
@ -101,8 +102,8 @@
|
||||||
<div class="ml-4">
|
<div class="ml-4">
|
||||||
<SettingCombobox
|
<SettingCombobox
|
||||||
comboboxPlaceholder={$t('language')}
|
comboboxPlaceholder={$t('language')}
|
||||||
{selectedOption}
|
selectedOption={langOptions.find(({ value }) => value === $lang) || defaultLangOption}
|
||||||
options={langs.map((lang) => ({ label: lang.name, value: lang.code }))}
|
options={langOptions}
|
||||||
title={$t('language')}
|
title={$t('language')}
|
||||||
subtitle={$t('language_setting_description')}
|
subtitle={$t('language_setting_description')}
|
||||||
onSelect={(combobox) => handleLanguageChange(combobox?.value)}
|
onSelect={(combobox) => handleLanguageChange(combobox?.value)}
|
||||||
|
|
|
@ -244,7 +244,7 @@ export const locales = [
|
||||||
{ code: 'zu-ZA', name: 'Zulu (South Africa)' },
|
{ code: 'zu-ZA', name: 'Zulu (South Africa)' },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const fallbackLang = 'en-US';
|
export const defaultLang = { name: 'English', code: 'en', loader: () => import('$lib/i18n/en.json') };
|
||||||
|
|
||||||
export const langs = [
|
export const langs = [
|
||||||
{ name: 'Arabic', code: 'ar', loader: () => import('$lib/i18n/ar.json') },
|
{ name: 'Arabic', code: 'ar', loader: () => import('$lib/i18n/ar.json') },
|
||||||
|
@ -252,7 +252,7 @@ export const langs = [
|
||||||
{ name: 'Czech', code: 'cs', loader: () => import('$lib/i18n/cs.json') },
|
{ name: 'Czech', code: 'cs', loader: () => import('$lib/i18n/cs.json') },
|
||||||
{ name: 'Danish', code: 'da', loader: () => import('$lib/i18n/da.json') },
|
{ name: 'Danish', code: 'da', loader: () => import('$lib/i18n/da.json') },
|
||||||
{ name: 'German', code: 'de', loader: () => import('$lib/i18n/de.json') },
|
{ name: 'German', code: 'de', loader: () => import('$lib/i18n/de.json') },
|
||||||
{ name: 'English', code: 'en', loader: () => import('$lib/i18n/en.json') },
|
defaultLang,
|
||||||
{ name: 'Spanish', code: 'es', loader: () => import('$lib/i18n/es.json') },
|
{ name: 'Spanish', code: 'es', loader: () => import('$lib/i18n/es.json') },
|
||||||
{ name: 'Finnish', code: 'fi', loader: () => import('$lib/i18n/fi.json') },
|
{ name: 'Finnish', code: 'fi', loader: () => import('$lib/i18n/fi.json') },
|
||||||
{ name: 'French', code: 'fr', loader: () => import('$lib/i18n/fr.json') },
|
{ name: 'French', code: 'fr', loader: () => import('$lib/i18n/fr.json') },
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { Theme } from '$lib/constants';
|
import { Theme, defaultLang } from '$lib/constants';
|
||||||
import { persisted } from 'svelte-local-storage-store';
|
import { persisted } from 'svelte-local-storage-store';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export const locale = persisted<string | undefined>('locale', undefined, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const lang = persisted<string | undefined>('lang', undefined, {
|
export const lang = persisted('lang', defaultLang.code, {
|
||||||
serializer: {
|
serializer: {
|
||||||
parse: (text) => text,
|
parse: (text) => text,
|
||||||
stringify: (object) => object ?? '',
|
stringify: (object) => object ?? '',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { fallbackLang, langs } from '$lib/constants';
|
import { defaultLang, langs } from '$lib/constants';
|
||||||
import { lang } from '$lib/stores/preferences.store';
|
import { lang } from '$lib/stores/preferences.store';
|
||||||
import { defaults } from '@immich/sdk';
|
import { defaults } from '@immich/sdk';
|
||||||
import { init, register } from 'svelte-i18n';
|
import { init, register } from 'svelte-i18n';
|
||||||
|
@ -20,7 +20,7 @@ export const load = (async ({ fetch }) => {
|
||||||
|
|
||||||
const preferenceLang = get(lang);
|
const preferenceLang = get(lang);
|
||||||
|
|
||||||
await init({ fallbackLocale: fallbackLang, initialLocale: preferenceLang || fallbackLang });
|
await init({ fallbackLocale: preferenceLang === 'dev' ? 'dev' : defaultLang.code, initialLocale: preferenceLang });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
Loading…
Reference in a new issue