# node: getLocale URL: https://generaltranslation.com/ja/docs/node/api/get-locale.mdx --- title: getLocale description: getLocale 関数の API リファレンス --- ## 概要 `getLocale` 関数は、現在のリクエストコンテキストのロケールを返します。 ```js import { getLocale } from 'gt-node'; const locale = getLocale(); // 'en-US' ``` **リクエストコンテキストが必要です:** `getLocale` は、どのロケールを使うか判断できるよう、[`withGT`](/docs/node/api/with-gt) のコールバック内で呼び出す必要があります。 ## リファレンス ### パラメータ なし。 ### 戻り値 `string` — 現在の BCP 47 [ロケールコード](/docs/core/locales) (例: `'en-US'`) 。 *** ## 例 ### 基本的な使い方 ```js 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(); }); }); ``` *** ## 次のステップ * 対応ロケールの完全な一覧は、[`getLocales`](/docs/node/api/get-locales)を参照してください。 * ロケールのメタデータは、[`getLocaleProperties`](/docs/node/api/get-locale-properties)を参照してください。