# node: getLocale URL: https://generaltranslation.com/zh/docs/node/api/get-locale.mdx --- title: getLocale description: getLocale 函数的 API 参考文档 --- ## 概述 `getLocale` 函数返回当前请求上下文的区域设置。 ```js import { getLocale } from 'gt-node'; const locale = getLocale(); // 'en-US' ``` **必须提供请求上下文:** 必须在 [`withGT`](/docs/node/api/with-gt) 回调内调用 `getLocale`,这样它才能确定应使用哪个区域设置。 ## 参考文档 ### 参数 无。 ### 返回值 `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)。