Internationalization¶
The frontend supports English and French via i18next.
Setup¶
src/i18n.js configures:
- Detection: Browser language via
i18next-browser-languagedetector - Fallback: English (
en) - Namespace:
common(single namespace) - Translation files:
src/Locales/{en,fr}/common.json
Usage¶
import { useTranslation } from "react-i18next";
function MyComponent() {
const { t } = useTranslation();
return <h1>{t("welcome.title")}</h1>;
}
Random translations¶
For variety in UI text (e.g., placeholder messages):
import i18n from "../i18n";
const placeholder = i18n.randomT("chat.placeholders");
// Returns a random item from the translation array
Adding translations¶
- Add the key to both
src/Locales/en/common.jsonandsrc/Locales/fr/common.json - Use the key via
t("section.key")in your component - For arrays (random selection), use
i18n.randomT("section.key")
Adding a new language¶
- Create
src/Locales/{code}/common.json - Add the language code to
supportedLngsinsrc/i18n.js - Translate all keys from the English file