# gt-node: General Translation Node.js SDK: getLocale
URL: https://generaltranslation.com/ja/docs/node/reference/functions/get-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: General Translation gt-node で現在のリクエストのアクティブなロケールを取得します。getLocale の API リファレンス。

アクティブなロケールを BCP 47 コードとして返します。リクエストに紐づいたロケールを取得するには、[`withGT`](/docs/node/reference/functions/with-gt) スコープ内で呼び出してください。

## 概要 [#overview]

引数を指定せずに `getLocale` を呼び出すと、現在アクティブな BCP 47 のロケールコードを取得できます。

```ts
import { getLocale } from 'gt-node';

const locale = getLocale(); // 'en-US'
```

シグネチャ:

```ts
getLocale(): string
```

*注: `getLocale` は、使用するロケールを判別できるよう、[`withGT`](/docs/node/reference/functions/with-gt) のコールバック内で呼び出す必要があります。*

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

* **リクエストスコープ。** 親の [`withGT`](/docs/node/reference/functions/with-gt) 呼び出しに紐づけられたロケールを読み取ります。
* **同期的。** 即座に戻り、`await` は不要です。

## パラメータ [#parameters]

`getLocale` にパラメータはありません。

## 戻り値 [#returns]

**型** `string`

現在の BCP 47 ロケールコード (例: `'en-US'`) 。

## 例 [#examples]

```ts title="handler.js"
// 基本的な使い方
import { withGT, getLocale } from 'gt-node';

app.use((req, res, next) => {
  const locale = req.headers['accept-language']?.split(',')[0] || 'en-US';
  withGT(locale, () => {
    console.log(getLocale()); // 'en-US'
    next();
  });
});
```

## Sitemap

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