# General Translation React SDKs (gt-react, gt-next, gt-react-native): useLocale
URL: https://generaltranslation.com/ja/docs/react/reference/hooks/use-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: アクティブなロケールを取得します。useLocale の API リファレンス。

`useLocale` フックは、[`<GTProvider>`](/docs/react/reference/components/gt-provider) のコンテキストから、`en-US` などの BCP 47 ロケールコードとしてユーザーの現在のロケールを返します。

*`gt-react`、`gt-next`、`gt-tanstack-start`、`gt-react-native` で利用できます。*

## 概要 [#overview]

アクティブなロケールを取得するには、`useLocale` を呼び出します。

*例では `gt-react` からインポートしています。代わりにご使用のフレームワークのパッケージからインポートしてください。*

```tsx
import { useLocale } from 'gt-react';

export default function CurrentLocale() {
  const locale = useLocale(); // [!code highlight]
  return <p>Current locale: {locale}</p>;
}
```

*注: `gt-react` では、[`<GTProvider>`](/docs/react/reference/components/gt-provider) の配下で `useLocale` を呼び出してください。`gt-next` では、同期サーバーコンポーネント内でも使用できます。*

## 仕組み [#how-it-works]

サポートされていないロケールが要求された場合は、フォールバックが選択されます。

* ユーザーのブラウザーに複数の優先ロケールが設定されていて、そのうち 1 つがサポートされている場合は、最も適したサポート対象の言語が使用されます。
* それ以外の場合、2 つのロケールが同じ言語を共有している場合 (たとえば `en-US` と `en-GB`) 、その言語を共有するサポート対象のロケールが使用されます。
* どちらにも当てはまらない場合は、[デフォルトロケール](/docs/react/reference/config#default-locale) が使用されます。

## 戻り値 [#returns]

**型** `string`

ユーザーの現在のロケール (例: `en-US`) 。

## メモ [#notes]

* 非同期の App Router コンポーネントでは、代わりに [`getLocale`](/docs/react/nextjs/reference/functions/get-locale) を使用します。
* ロケールを変更するには [`useSetLocale`](/docs/react/reference/hooks/use-set-locale) を、ソース ロケールを読み取るには [`useDefaultLocale`](/docs/react/reference/hooks/use-default-locale) を使用します。

## Sitemap

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