i18next-translation
Find hardcoded user-facing strings, replace them with t() calls, and add the corresponding keys to both locale files (he.json AND en.json). Ported from cursor-rules; the conventions are owned by i18n-localization, applied in components by frontend-developer.
Per-app i18n lib: i18next/react-i18next on the dashboards, next-i18next on management, next-intl on the consumer app. Match the app you are in.
When NOT to useβ
- Technical values (IDs, class names, log messages, keys).
- 3rd-party component props that expect non-translated values.
- Strings already wrapped in
t().
Workflowβ
1. Detect hardcoded stringsβ
- JSX text nodes:
<h1>Welcome back</h1>,<span>Submit</span>. - String literals in user-facing attributes:
placeholder="Searchβ¦",aria-label="Close". - Button/link labels, headings, error messages, tooltips, toasts.
2. Convert to t()β
// before
<h1>Welcome back</h1>
<button>Submit</button>
// after
import { useTranslation } from 'react-i18next';
const MyComponent = () => {
const { t } = useTranslation(); // top of the component, namespace if applicable
return <><h1>{t('welcomeBack')}</h1><button>{t('submit')}</button></>;
};
Add the useTranslation import + const { t } = useTranslation() if missing.
3. Key namingβ
- camelCase:
welcomeBack,submitForm,noResultsβ descriptive, context-aware (userProfileTitle, nottitle). - Namespaces / dot-notation:
common.cancel,dashboard.org.sectionName. - Check the existing locale files for the project's established patterns before adding.
4. Generate keys in BOTH localesβ
Add to both src/i18n/en.json and src/i18n/he.json β never one without the other (Hebrew is first-class, not a stub). Keep the key sets identical.
// en.json // he.json
{ "welcomeBack": "Welcome back", "submit": "Submit" } { "welcomeBack": "Χ©ΧΧΧ Χ©ΧΧ", "submit": "Χ©ΧΧ" }
5. Type-safety + legacy migrationβ
- Prefer typed resources (
i18next.d.ts/useTranslation<'ns'>()) so a bad key fails compile. - If you see
const { t } = useAppData();(legacy), migrate it touseTranslationand move the strings into the locale files.
Outputβ
The edited component (strings β t()) + the new keys added to both he.json and en.json, reported with the namespace used. The wording of customer copy is product/PRD Β§7.4; you own the key + the mechanism.
Cross-referencesβ
i18n-localizationβ owns the key conventions + RTL + locale files.frontend-developerβ wirest()into components.- Source: cursor-rules
bewith-i18next-translationskill +bewith-i18n-conventions.mdc.