Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

refactor(i18n): extract SUPPORTED_LANGUAGES to avoid duplication

Isaias Tavares91f7c3778fcd
diff --git a/client/src/i18n/TranslationContext.tsx b/client/src/i18n/TranslationContext.tsx
index aee8ff713..83a2a1273 100644
--- a/client/src/i18n/TranslationContext.tsx
+++ b/client/src/i18n/TranslationContext.tsx
@@ -14,25 +14,11 @@ 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'
-type TranslationStrings = Record<string, string | { name: string; category: string }[]>
+export { SUPPORTED_LANGUAGES }
-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
+type TranslationStrings = Record<string, string | { name: string; category: string }[]>
const translations: Record<string, TranslationStrings> = { de, en, es, fr, hu, it, ru, zh, 'zh-TW': zhTw, nl, ar, br, cs, pl }
const LOCALES: Record<string, string> = { 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' }
diff --git a/client/src/i18n/supportedLanguages.ts b/client/src/i18n/supportedLanguages.ts
new file mode 100644
index 000000000..496e34b24
--- /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 9e56e505b..f10ff7d81 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<SettingsState>((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 } }))
},