This project uses next-intl for multi-language support. Currently, English (en) and Spanish (es) are configured.
src/i18n/routing.ts- Locale routing configurationsrc/i18n/messages/en.json- English translationssrc/i18n/messages/es.json- Spanish translationssrc/middleware.ts- next-intl middleware for locale detection
To complete the i18n setup, install next-intl:
npm install next-intlAfter installing next-intl, update your next.config.js to enable i18n support if not already configured.
Import the useTranslations hook from next-intl to access translations:
import { useTranslations } from 'next-intl';
export default function MyComponent() {
const t = useTranslations('farm');
return (
<div>
<h1>{t('title')}</h1>
<p>{t('deposit')}</p>
</div>
);
}Translations are organized by namespace:
common.*- Global UI labels (buttons, loading states, etc.)farm.*- Farm and pool-related stringsleaderboard.*- Leaderboard page stringswallet.*- Wallet connection strings
- Add the key to both
src/i18n/messages/en.jsonandsrc/i18n/messages/es.json - Use
useTranslations()in your component with the namespace - Access the translation:
t('key')
- English (
en) - Default - Spanish (
es)
To add another language:
- Create
src/i18n/messages/[locale].json - Add locale to
routing.localesinsrc/i18n/routing.ts - Add translation strings for all keys
The middleware automatically detects locale from the URL path. Routes are structured as:
/en/farm- English version/es/farm- Spanish version/farm- Uses default locale (English)
Use the Link component from next-intl/navigation to navigate between locales:
import { Link } from '@/i18n/routing';
export function LanguageSwitcher() {
return (
<div>
<Link href="/farm" locale="en">English</Link>
<Link href="/farm" locale="es">Español</Link>
</div>
);
}