Custom i18n system with typed translation dictionaries (~570 keys), LanguageProvider context, and useTranslation hook. All 31 components and pages wired with t() calls. Chatbot backend passes language hint to Claude for Ukrainian responses. Language preference persists via localStorage. SEO meta tags and html lang attribute update dynamically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 KiB
1 KiB
Quickstart: Multi-Language Support
Adding a New Translation
- Open
src/i18n/types.tsand add the key to theTranslationsinterface - Add the English value in
src/i18n/en.ts - Add the Ukrainian value in
src/i18n/uk.ts - TypeScript will error if any file is missing the new key
Using Translations in a Component
import { useTranslation } from '../i18n';
function MyComponent() {
const { t, lang } = useTranslation();
return <h1>{t('my.section.title')}</h1>;
}
Formatting Dates by Locale
const { lang } = useTranslation();
const locale = lang === 'uk' ? 'uk-UA' : 'en-GB';
const formatted = new Date(dateStr).toLocaleDateString(locale, {
year: 'numeric', month: 'long', day: 'numeric'
});
Adding a New Language (Future)
- Add the new code to the
Langtype intypes.ts - Create a new translation file (e.g.,
de.ts) satisfyingTranslations - Register it in
LanguageContext.tsxtranslations map - Add the language option to the Header toggle