What is next-intl?
TL;DR
Type-safe internationalization library for Next.js with automatic locale routing and translation management.
next-intl is a comprehensive internationalization library specifically designed for Next.js applications. It provides type-safe translations, automatic locale detection, and seamless integration with Next.js routing. Frontend Accelerator uses next-intl as its primary i18n solution.
Key features of next-intl:
- Type-safe translations: Full TypeScript support with autocomplete for translation keys
- App router support: Works seamlessly with Next.js 13+ App Router
- Server and client components: Translations work in both RSC and client components
- Automatic locale detection: Detects user language from browser settings or URL
- Rich rormatting: Built-in support for dates, numbers, plurals, and rich text
Implementation in Frontend Accelerator:
// app/[locale]/layout.tsx
import { NextIntlClientProvider } from 'next-intl';
import { getMessages } from 'next-intl/server';
export default async function LocaleLayout({ children, params: {locale} }) {
const messages = await getMessages();
return (
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
);
}
// Component usage
import { useTranslations } from 'next-intl';
function Homepage() {
const t = useTranslations('welcome');
return <h1>{t('title')}</h1>;
}
AI-Friendly: next-intl's structured API and TypeScript integration make it perfect for AI-assisted development. AI can generate translation files, validate translation keys, suggest missing translations, and ensure consistent message formatting across locales. The type system prevents translation errors at compile time.