# gt-next: General Translation Next.js SDK: useLocaleDirection URL: https://generaltranslation.com/zh/docs/next/api/helpers/use-locale-direction.mdx --- title: useLocaleDirection description: useLocaleDirection Hook 的 API 参考 --- {/* 自动生成:请勿直接修改。请改为编辑 content/docs-templates/ 中的模板。 */} ## 概述 `useLocaleDirection` Hook 用于从 [`` 上下文](/docs/next/api/components/gtprovider) 中获取当前或指定区域设置的文本方向 (`'ltr'` 或 `'rtl'`) 。 `useLocaleDirection` 是一个客户端 Hook,*只能在客户端组件中使用*。 请确保你的应用已由 [``](/docs/next/api/components/gtprovider) 包裹。 ## 参考 ### 参数 | 参数 | 类型 | 描述 | | -------- | -------------- | --------------------------------------------------------- | | `locale` | `string` (可选) | BCP 47 区域设置代码 (例如 `'ar'`、`'en-US'`) 。如果省略,则使用上下文中的当前区域设置。 | ### 返回值 `'ltr' | 'rtl'` — 该区域设置对应的文本方向。 *** ## 示例 ### 获取当前区域设置的书写方向 ```jsx title="DirectionWrapper.jsx" copy 'use client'; import { useLocaleDirection } from 'gt-next'; export default function DirectionWrapper({ children }) { const dir = useLocaleDirection(); // [!code highlight] return
{children}
; } ``` ### 获取特定区域设置的书写方向 ```jsx title="SpecificDirection.jsx" copy 'use client'; import { useLocaleDirection } from 'gt-next'; export default function SpecificDirection() { const dir = useLocaleDirection('ar'); // 'rtl' [!code highlight] return

Arabic text direction: {dir}

; } ``` *** ## 说明 * 这个 Hook 始终是同步的。 * 可用于给元素设置 `dir` 属性,以支持 RTL。 ## 后续步骤