# General Translation React SDKs (gt-react, gt-next, gt-react-native): getLocale URL: https://generaltranslation.com/zh/docs/react/tanstack-start/reference/functions/get-locale.mdx --- title: getLocale description: 使用 General Translation 读取当前 TanStack Start 运行时区域设置。getLocale 的 API 参考。 --- `getLocale` 函数会返回与当前服务器请求或浏览器关联的区域设置代码,采用 BCP 47 格式。请从 `gt-tanstack-start` 导入。 ## 概览 [#overview] ```ts import { getLocale } from 'gt-tanstack-start'; const locale = getLocale(); // 'en-US' ``` ```ts getLocale(): string ``` ## 工作原理 [#how-it-works] 在服务器端,`getLocale` 会读取由 [`gtMiddleware`](/docs/react/tanstack-start/reference/functions/gt-middleware) 创建的请求级区域设置值。启用 `localeRouting` 后,中间件会依次从路径前缀、区域设置 cookie、`Accept-Language` header 和 `defaultLocale` 中解析区域设置。未启用区域设置路由时,则从 cookie 开始解析。 在浏览器中,它会读取由 [`initializeGT`](/docs/react/reference/config#initialize) 初始化的 condition store。该函数是同步的。在活动中的中间件请求层级之外进行服务器端调用会抛出异常。 **v11 变更:** 请使用 `getLocale()` 代替已弃用的 `parseLocale()`,并从 `gt-tanstack-start` 而不是 `gt-tanstack-start/server` 导入 Runtime helper。 ## 返回值 [#returns] **类型** `string` 当前请求的区域设置。 ## 示例 [#example] ```ts import { createServerFn } from '@tanstack/react-start'; import { getLocale } from 'gt-tanstack-start'; export const loadLocale = createServerFn({ method: 'GET' }).handler(() => { return getLocale(); }); ```