# gt-react: General Translation React SDK: useLocales URL: https://generaltranslation.com/zh/docs/react/api/helpers/use-locales.mdx --- title: useLocales description: useLocales Hook 的 API 参考文档 --- {/* 自动生成:请勿直接编辑。请改为编辑 content/docs-templates/ 中的 template。 */} ## 概述 `useLocales` Hook 用于从 [`` 上下文](/docs/react/api/components/gtprovider) 中获取支持的区域设置列表。 `useLocales` 是一个客户端 Hook,*只能在客户端组件中使用*。 请确保你的应用已使用 [``](/docs/react/api/components/gtprovider) 包裹。 ## 参考 ### 返回值 `string[]` — 一个由 BCP 47 [区域设置代码](/docs/core/locales) 组成的数组,表示支持的区域设置,例如 `['en-US', 'fr', 'ja']`。 *** ## 示例 ### 基本用法 ```jsx title="LocaleList.jsx" copy 'use client'; import { useLocales } from 'gt-react'; export default function LocaleList() { const locales = useLocales(); // [!code highlight] return ( ); } ``` *** ## 注意事项 * `useLocales` Hook 依赖 [``](/docs/react/api/components/gtprovider) 获取上下文。请确保在根层使用 provider 包裹你的应用。 * `useLocales` 仅限客户端使用。 ## 后续步骤 * 了解如何在 [`gt.config.json`](/docs/react/api/config/gt-config-json) 中配置支持的区域设置。