- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres (zonder configuratie ongewijzigd gedrag) - Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007) - Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability) met bijbehorende tests - Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina - CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED - Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import i18n from 'i18next';
|
|
import { initReactI18next } from 'react-i18next';
|
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
import enTranslation from './locales/en/translation.json';
|
|
import nlTranslation from './locales/nl/translation.json';
|
|
import { getAppConfig } from '@/lib/config';
|
|
|
|
export const SUPPORTED_LANGUAGES = ['en', 'nl'] as const;
|
|
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
|
|
|
export const LANGUAGE_LABELS: Record<SupportedLanguage, string> = {
|
|
en: 'English',
|
|
nl: 'Nederlands',
|
|
};
|
|
|
|
/**
|
|
* Language resolution order: a stored user choice always wins; otherwise the build-time
|
|
* VITE_DEFAULT_LANGUAGE; otherwise the browser language (the behaviour before this option existed).
|
|
*/
|
|
export function languageDetection(defaultLanguage: SupportedLanguage | undefined) {
|
|
return defaultLanguage === undefined
|
|
? { order: ['localStorage', 'navigator'], fallbackLng: 'en' }
|
|
: { order: ['localStorage'], fallbackLng: defaultLanguage };
|
|
}
|
|
|
|
const detectionSetup = languageDetection(getAppConfig().defaultLanguage);
|
|
|
|
// Both supported locales are bundled eagerly so the detected language is
|
|
// available immediately on init — no async gap that would cause an English flash.
|
|
void i18n
|
|
.use(LanguageDetector)
|
|
.use(initReactI18next)
|
|
.init({
|
|
resources: {
|
|
en: { translation: enTranslation },
|
|
nl: { translation: nlTranslation },
|
|
},
|
|
fallbackLng: detectionSetup.fallbackLng,
|
|
supportedLngs: SUPPORTED_LANGUAGES as unknown as string[],
|
|
nonExplicitSupportedLngs: true,
|
|
interpolation: { escapeValue: false },
|
|
detection: {
|
|
order: detectionSetup.order,
|
|
caches: ['localStorage'],
|
|
},
|
|
react: { useSuspense: false },
|
|
});
|
|
|
|
/** Switch to a supported locale and persist the choice via the detector cache. */
|
|
export async function changeLanguage(lng: SupportedLanguage): Promise<void> {
|
|
await i18n.changeLanguage(lng);
|
|
}
|
|
|
|
export default i18n;
|