# General Translation React SDKs (gt-react, gt-next, gt-react-native): registerLocale
URL: https://generaltranslation.com/zh/docs/react/nextjs/reference/functions/register-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 在 General Translation 中为 Next.js App Router 服务器端代码注册区域设置。registerLocale 的 API 参考。

`registerLocale` 函数用于为当前 App Router 请求上下文设置区域设置。在无法使用 `next/root-params` 时，请在 Route Handlers 和元数据图片 handler 中使用它。有关 handler 示例，请参阅[注册请求区域设置](/docs/react/nextjs/registering-request-locales)。

`registerLocale` 仅限服务器端使用，不适用于 Pages Router。

## 概览 [#overview]

在请求处理程序中，先调用 `registerLocale`，再调用任何其他 `gt-next` 服务器函数。

```tsx
import { registerLocale } from 'gt-next/server';

registerLocale('fr');
```

## 参数 [#parameters]

| 参数       | 描述            | 类型       | 可选 | 默认值 |
| -------- | ------------- | -------- | -- | --- |
| `locale` | 为当前请求注册的区域设置。 | `string` | 否  | —   |

不受支持的 `locale` 值会按照你的 General Translation 区域设置配置回退。

## 返回值 [#returns]

**类型** `void`

## 示例 [#example]

```tsx title="app/[locale]/opengraph-image.tsx"
import { ImageResponse } from 'next/og';
import { getGT, registerLocale } from 'gt-next/server';

export default async function Image({ params }) {
  const { locale } = await params;
  registerLocale(locale);

  const gt = await getGT();
  return new ImageResponse(<div>{gt('Welcome')}</div>);
}
```

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
