# General Translation Platform: getLocaleDirection URL: https://generaltranslation.com/ja/docs/platform/core/reference/utility-functions/locales/get-locale-direction.mdx --- title: getLocaleDirection description: GT インスタンスなしでロケールのテキスト方向を返します。getLocaleDirection の API リファレンス。 --- [`getLocaleDirection`](/docs/platform/core/reference/gt-class-methods/locales/get-locale-direction) は、General Translation の Core ライブラリに含まれるスタンドアロンのユーティリティ関数で、ロケールのテキスト方向 (左から右、または右から左) を返します。主に、ロケールに応じて HTML 要素の `dir` 属性を設定するために使用されます。 ## 概要 [#overview] `generaltranslation` から `getLocaleDirection` を直接インポートし、ロケールコードを渡して呼び出します。API Key や [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは必要ありません。インスタンスベースの同等機能を使う場合は、代わりに [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`getLocaleDirection`](/docs/platform/core/reference/gt-class-methods/locales/get-locale-direction) メソッドを使用してください。 ```typescript import { getLocaleDirection } from 'generaltranslation'; const direction = getLocaleDirection('ar-SA'); console.log(direction); // "rtl" const englishDirection = getLocaleDirection('en-US'); console.log(englishDirection); // "ltr" ``` シグネチャ: ```typescript getLocaleDirection(locale: string): 'ltr' | 'rtl' ``` ## 仕組み [#how-it-works] この関数は、`Intl.Locale` API の `textInfo.direction` プロパティを使用します。 1. 指定されたロケールに対して `Intl.Locale` オブジェクトを作成します。 2. `textInfo.direction` プロパティを読み取り、言語固有のテキスト方向を取得します。 3. 右から左に記述する言語には `'rtl'` を、それ以外の言語には `'ltr'` を返します。 4. ロケールが無効な場合やエラーが発生した場合は、デフォルトで `'ltr'` を返します。 ### RTL言語の認識 次のような右から左に書く言語を自動的に検出します。 * **アラビア語** (`ar`, `ar-SA`, `ar-EG`, `ar-AE` など) * **ヘブライ語** (`he`, `he-IL`) * **ペルシア語/ファルシー語** (`fa`, `fa-IR`) * **ウルドゥー語** (`ur`, `ur-PK`, `ur-IN`) * **パシュトー語** (`ps`) * **シンド語** (`sd`) * **クルド語 (ソラニー) ** (`ckb`) * その他のRTLスクリプト。 ### エラー処理 * 無効または形式が不正なロケールコードは、デフォルトで `'ltr'` になります。 * 無効な入力でも例外はスローされません。 ## パラメータ [#parameters] | パラメータ | 説明 | Type | 任意 | デフォルト | | ------------------- | --------------------------------- | -------- | --- | ----- | | [`locale`](#locale) | テキスト方向を確認する対象の BCP-47 ロケールコード。 | `string` | いいえ | — | ### `locale` [#locale] **型** `string` · **必須** テキスト方向を確認する対象の BCP-47 ロケールコード。 ## 戻り値 [#returns] **型** `'ltr' | 'rtl'` ロケールのテキスト方向: * `'ltr'`: 左から右 (英語、スペイン語、フランス語、ドイツ語、中国語、日本語を含む、ほとんどの言語) 。 * `'rtl'`: 右から左 (アラビア語、ヘブライ語、ペルシア語、ウルドゥー語、その他のセム語系・中東の言語) 。 ## 例 [#examples] ```typescript import { getLocaleDirection } from 'generaltranslation'; // 左から右に書く言語 console.log(getLocaleDirection('en-US')); // "ltr" console.log(getLocaleDirection('es-ES')); // "ltr" console.log(getLocaleDirection('fr-FR')); // "ltr" console.log(getLocaleDirection('ja-JP')); // "ltr" console.log(getLocaleDirection('zh-CN')); // "ltr" // 右から左に書く言語 console.log(getLocaleDirection('ar-SA')); // "rtl" console.log(getLocaleDirection('he-IL')); // "rtl" console.log(getLocaleDirection('fa-IR')); // "rtl" console.log(getLocaleDirection('ur-PK')); // "rtl" ``` ## メモ [#notes] * 左から右へ記述するすべての言語 (世界の大半の言語) で `'ltr'` を返します。 * 右から左へ記述する言語 (アラビア語、ヘブライ語、ペルシャ語など) では `'rtl'` を返します。 * 正確に判定するため、最新の `Intl.Locale` API を使用します。 * すべての BCP-47 ロケールコードで動作します。