跳转到内容

添加新 Locale

打开 tyndale.config.json,并将 locale 代码添加到 locales 数组中:

{
"defaultLocale": "en",
"locales": ["es", "fr", "ja", "de"]
}

defaultLocale 是你的源语言,因此它不能出现在 locales 中。

然后运行:

Terminal window
npx tyndale translate

translate 会先自动运行提取,然后为新的 locale 生成翻译;现有的 locale 文件会保持不变,除非需要清理过期条目。

使用 localeAliases 将变体代码映射到规范代码:

{
"localeAliases": {
"pt-BR": "pt",
"zh-TW": "zh"
}
}

Tyndale 会检测 RTL locale,但不会替你修改 <html dir>。请结合当前的 locale 辅助函数显式设置方向:

app/[locale]/layout.tsx
import { getDirection } from 'tyndale-next/server';
export default async function RootLayout({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
return (
<html lang={locale} dir={getDirection(locale)}>
<body>{children}</body>
</html>
);
}

在客户端组件中,当你需要在已渲染的 UI 内使用当前方向值时,请使用 useDirection()