# General Translation Platform: getLocaleDirection
URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/locales/get-locale-direction.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: ロケールのテキストの方向を返します。getLocaleDirection の API リファレンス。

General Translation は、左から右で記述する言語には `'ltr'` を、右から左で記述する言語には `'rtl'` を返します。

## 概要 [#overview]

[`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスに対して、必要に応じてロケールコードを指定して `getLocaleDirection` を呼び出します。省略した場合は、そのインスタンスの `targetLocale` が使用されます。

```typescript
const gt = new GT({ sourceLocale: 'en', targetLocale: 'ar' });

const direction = gt.getLocaleDirection('ar');
console.log(direction); // "rtl"

const englishDirection = gt.getLocaleDirection('en-US');
console.log(englishDirection); // "ltr"
```

シグネチャ:

```typescript
getLocaleDirection(locale?: string): 'ltr' | 'rtl'
```

*注: `getLocaleDirection` は `Intl.Locale` を使用してローカルで動作するため、APIキーは必要ありません。`locale` を省略した場合は、インスタンスの `targetLocale` が使用されます。`GT` インスタンスを使わずに参照する場合は、スタンドアロン版の [`getLocaleDirection`](/docs/platform/core/reference/utility-functions/locales/get-locale-direction) を参照してください。*

## 仕組み [#how-it-works]

* **direction の判定。** 左から右の言語 (世界の大半の言語) では `'ltr'`、右から左の言語 (アラビア語、ヘブライ語、ペルシア語、ウルドゥー語など) では `'rtl'` を返します。
* **ロケールのフォールバック。** `locale` が省略されている場合は、インスタンスの `targetLocale` が使用されます。
* **ロケール未指定。** ロケールが指定されておらず、かつインスタンスに `targetLocale` が設定されていない場合は、`Error` をスローします。

## パラメータ [#parameters]

| パラメータ               | 説明                                | 型        | 任意 | デフォルト               |
| ------------------- | --------------------------------- | -------- | -- | ------------------- |
| [`locale`](#locale) | テキストの方向を確認する対象の BCP-47 ロケールコード。 | `string` | はい | `this.targetLocale` |

### `locale` [#locale]

**型** `string` · **省略可能** · **デフォルト** `this.targetLocale`

テキストの方向を確認する BCP-47 ロケールコードです。指定しない場合は、このインスタンスの `targetLocale` を使用します。

## 戻り値 [#returns]

**型** `'ltr' | 'rtl'`

ロケールのテキストの方向:

* `'ltr'`: 左から右 (ほとんどの言語) 。
* `'rtl'`: 右から左 (アラビア語、ヘブライ語、ペルシア語、ウルドゥー語など) 。

ロケールが指定されておらず、インスタンスに `targetLocale` も設定されていない場合は、`Error` がスローされます。

## 例 [#examples]

```typescript
const gt = new GT({ sourceLocale: 'en', targetLocale: 'ar' });

// 異なる言語の方向を確認する
console.log(gt.getLocaleDirection()); // "rtl" (targetLocale 'ar' を使用)
console.log(gt.getLocaleDirection('en')); // "ltr"
console.log(gt.getLocaleDirection('ar')); // "rtl"
console.log(gt.getLocaleDirection('he')); // "rtl"
console.log(gt.getLocaleDirection('fa')); // "rtl"
console.log(gt.getLocaleDirection('fr')); // "ltr"
```

## メモ [#notes]

* 左から右に書くすべての言語 (世界の大半の言語) で `'ltr'` を返します。
* 右から左に書く言語 (アラビア語、ヘブライ語、ペルシア語など) で `'rtl'` を返します。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
