Implement multi-language support in Next.js with Google Antigravity including routing translations and formatting
# Internationalization for Google Antigravity
Multi-language support expands your audience. This guide establishes patterns for i18n in Google Antigravity projects.
## Next-Intl Setup
```typescript
// i18n.ts
import { getRequestConfig } from "next-intl/server";
export default getRequestConfig(async ({ locale }) => ({
messages: (await import(`./messages/${locale}.json`)).default,
}));
// middleware.ts
import createMiddleware from "next-intl/middleware";
export default createMiddleware({
locales: ["en", "es", "fr", "de"],
defaultLocale: "en",
});
export const config = {
matcher: ["/((?!api|_next|.*\\..*).*)"],
};
```
## Translation Files
```json
// messages/en.json
{
"common": {
"welcome": "Welcome to our app",
"login": "Log in",
"signup": "Sign up"
},
"home": {
"title": "Build amazing products",
"description": "The best platform for developers"
}
}
```
## Using Translations
```typescript
import { useTranslations } from "next-intl";
export function Header() {
const t = useTranslations("common");
return (
<header>
<h1>{t("welcome")}</h1>
<nav>
<a href="/login">{t("login")}</a>
<a href="/signup">{t("signup")}</a>
</nav>
</header>
);
}
```
## Date and Number Formatting
```typescript
import { useFormatter } from "next-intl";
export function PriceDisplay({ amount }: { amount: number }) {
const format = useFormatter();
return (
<span>
{format.number(amount, { style: "currency", currency: "USD" })}
</span>
);
}
export function DateDisplay({ date }: { date: Date }) {
const format = useFormatter();
return (
<time dateTime={date.toISOString()}>
{format.dateTime(date, { dateStyle: "long" })}
</time>
);
}
```
## Best Practices
1. **Namespace translations**: Organize by feature
2. **Pluralization**: Handle plural forms
3. **Date/number formatting**: Use locale-aware formatting
4. **SEO**: Generate hreflang tags
5. **Fallbacks**: Handle missing translationsThis i18n prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their i18n implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For i18n projects, consider mentioning your framework version, coding style, and any specific libraries you're using.