diff --git a/client/src/i18n/TranslationContext.tsx b/client/src/i18n/TranslationContext.tsx index aee8ff71..83a2a127 100644 --- a/client/src/i18n/TranslationContext.tsx +++ b/client/src/i18n/TranslationContext.tsx @@ -14,26 +14,12 @@ import ar from './translations/ar' import br from './translations/br' import cs from './translations/cs' import pl from './translations/pl' +import { SUPPORTED_LANGUAGES } from './supportedLanguages' + +export { SUPPORTED_LANGUAGES } type TranslationStrings = Record -export const SUPPORTED_LANGUAGES = [ - { value: 'de', label: 'Deutsch' }, - { value: 'en', label: 'English' }, - { value: 'es', label: 'Español' }, - { value: 'fr', label: 'Français' }, - { value: 'hu', label: 'Magyar' }, - { value: 'nl', label: 'Nederlands' }, - { value: 'br', label: 'Português (Brasil)' }, - { value: 'cs', label: 'Česky' }, - { value: 'pl', label: 'Polski' }, - { value: 'ru', label: 'Русский' }, - { value: 'zh', label: '简体中文' }, - { value: 'zh-TW', label: '繁體中文' }, - { value: 'it', label: 'Italiano' }, - { value: 'ar', label: 'العربية' }, -] as const - const translations: Record = { de, en, es, fr, hu, it, ru, zh, 'zh-TW': zhTw, nl, ar, br, cs, pl } const LOCALES: Record = { de: 'de-DE', en: 'en-US', es: 'es-ES', fr: 'fr-FR', hu: 'hu-HU', it: 'it-IT', ru: 'ru-RU', zh: 'zh-CN', 'zh-TW': 'zh-TW', nl: 'nl-NL', ar: 'ar-SA', br: 'pt-BR', cs: 'cs-CZ', pl: 'pl-PL' } const RTL_LANGUAGES = new Set(['ar']) diff --git a/client/src/i18n/supportedLanguages.ts b/client/src/i18n/supportedLanguages.ts new file mode 100644 index 00000000..496e34b2 --- /dev/null +++ b/client/src/i18n/supportedLanguages.ts @@ -0,0 +1,20 @@ +export const SUPPORTED_LANGUAGES = [ + { value: 'de', label: 'Deutsch' }, + { value: 'en', label: 'English' }, + { value: 'es', label: 'Español' }, + { value: 'fr', label: 'Français' }, + { value: 'hu', label: 'Magyar' }, + { value: 'nl', label: 'Nederlands' }, + { value: 'br', label: 'Português (Brasil)' }, + { value: 'cs', label: 'Česky' }, + { value: 'pl', label: 'Polski' }, + { value: 'ru', label: 'Русский' }, + { value: 'zh', label: '简体中文' }, + { value: 'zh-TW', label: '繁體中文' }, + { value: 'it', label: 'Italiano' }, + { value: 'ar', label: 'العربية' }, +] as const + +export type SupportedLanguageCode = typeof SUPPORTED_LANGUAGES[number]['value'] + +export const SUPPORTED_LANGUAGE_CODES = SUPPORTED_LANGUAGES.map(l => l.value) diff --git a/client/src/store/settingsStore.ts b/client/src/store/settingsStore.ts index 9e56e505..f10ff7d8 100644 --- a/client/src/store/settingsStore.ts +++ b/client/src/store/settingsStore.ts @@ -2,6 +2,7 @@ import { create } from 'zustand' import { settingsApi } from '../api/client' import type { Settings } from '../types' import { getApiErrorMessage } from '../types' +import { SUPPORTED_LANGUAGE_CODES } from '../i18n/supportedLanguages' interface SettingsState { settings: Settings @@ -64,8 +65,7 @@ export const useSettingsStore = create((set, get) => ({ // Used for automatic detection (browser/server default) — only explicit user // choices via the UI should be persisted. setLanguageTransient: (lang: string) => { - const supported = ['de', 'en', 'es', 'fr', 'hu', 'nl', 'br', 'cs', 'pl', 'ru', 'zh', 'zh-TW', 'it', 'ar'] - if (!supported.includes(lang)) return + if (!SUPPORTED_LANGUAGE_CODES.includes(lang)) return set((state) => ({ settings: { ...state.settings, language: lang } })) },