正在加载...
正在加载...
构建多语言 Next.js 应用所需的一切。CDN 驱动翻译、服务器端渲染和即时语言切换。
betterMiddleware() 从 URL 路径、Cookie 或 Accept-Language 头部检测用户语言区域。支持 Clerk 风格的回调模式,便于身份验证集成。
中间件配置指南Get up and running in 4 simple steps.
Add the SDK to your project
bun add @better-i18n/nextCreate your i18n config
export const i18n = createI18n({ ... })Add BetterI18nProvider to your layout
<BetterI18nProvider>Call useTranslations() in any component
const t = useTranslations("ns")better-i18n works with all major React frameworks out of the box.
| Feature | Next.js | Expo | Remix | Hono | TanStack |
|---|---|---|---|---|---|
| CDN Fetch | ✓ | ✓ | ✓ | ✓ | ✓ |
| ISR / Revalidation | ✓ | — | ✓ | — | ✓ |
| useSetLocale() | ✓ | ✓ | ✓ | ✓ | ✓ |
| useFormatter() | ✓ | ✓ | ✓ | ✓ | ✓ |
| LocaleDropdown | ✓ | ✓ | ✓ | ✓ | ✓ |
| SSR Support | ✓ | — | ✓ | ✓ | ✓ |
在 5 分钟内为您的 Next.js 应用添加国际化。 阅读完整指南
// i18n.config.ts
import { createI18n } from "@better-i18n/next";
export const i18n = createI18n({
project: "your-org/your-project",
defaultLocale: "en",
});
// middleware.ts
import { i18n } from "./i18n.config";
export default i18n.betterMiddleware();
// app/[locale]/layout.tsx
const messages = await i18n.getMessages(locale);
<BetterI18nProvider config={i18n.config} locale={locale} messages={messages}>
{children}
</BetterI18nProvider>
// Any component
const t = useTranslations("namespace");
return <h1>{t("title")}</h1>;创建免费账户,添加您的语言,开始翻译。加入数千个开发者的行列,为全球用户构建应用。