mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
refactor(i18n): extract SUPPORTED_LANGUAGES to avoid duplication
Move language list to supportedLanguages.ts so TranslationContext and settingsStore can import from a single source of truth, eliminating the hardcoded array in setLanguageTransient.
This commit is contained in:
@@ -14,26 +14,12 @@ import ar from './translations/ar'
|
|||||||
import br from './translations/br'
|
import br from './translations/br'
|
||||||
import cs from './translations/cs'
|
import cs from './translations/cs'
|
||||||
import pl from './translations/pl'
|
import pl from './translations/pl'
|
||||||
|
import { SUPPORTED_LANGUAGES } from './supportedLanguages'
|
||||||
|
|
||||||
|
export { SUPPORTED_LANGUAGES }
|
||||||
|
|
||||||
type TranslationStrings = Record<string, string | { name: string; category: string }[]>
|
type TranslationStrings = Record<string, string | { name: string; category: string }[]>
|
||||||
|
|
||||||
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<string, TranslationStrings> = { de, en, es, fr, hu, it, ru, zh, 'zh-TW': zhTw, nl, ar, br, cs, pl }
|
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' }
|
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' }
|
||||||
const RTL_LANGUAGES = new Set(['ar'])
|
const RTL_LANGUAGES = new Set(['ar'])
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -2,6 +2,7 @@ import { create } from 'zustand'
|
|||||||
import { settingsApi } from '../api/client'
|
import { settingsApi } from '../api/client'
|
||||||
import type { Settings } from '../types'
|
import type { Settings } from '../types'
|
||||||
import { getApiErrorMessage } from '../types'
|
import { getApiErrorMessage } from '../types'
|
||||||
|
import { SUPPORTED_LANGUAGE_CODES } from '../i18n/supportedLanguages'
|
||||||
|
|
||||||
interface SettingsState {
|
interface SettingsState {
|
||||||
settings: Settings
|
settings: Settings
|
||||||
@@ -64,8 +65,7 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
|
|||||||
// Used for automatic detection (browser/server default) — only explicit user
|
// Used for automatic detection (browser/server default) — only explicit user
|
||||||
// choices via the UI should be persisted.
|
// choices via the UI should be persisted.
|
||||||
setLanguageTransient: (lang: string) => {
|
setLanguageTransient: (lang: string) => {
|
||||||
const supported = ['de', 'en', 'es', 'fr', 'hu', 'nl', 'br', 'cs', 'pl', 'ru', 'zh', 'zh-TW', 'it', 'ar']
|
if (!SUPPORTED_LANGUAGE_CODES.includes(lang)) return
|
||||||
if (!supported.includes(lang)) return
|
|
||||||
set((state) => ({ settings: { ...state.settings, language: lang } }))
|
set((state) => ({ settings: { ...state.settings, language: lang } }))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user