# General Translation Platform: getLocaleDirection
URL: https://generaltranslation.com/en-US/docs/platform/core/reference/utility-functions/locales/get-locale-direction.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Return text direction for a locale without a GT instance. API reference for getLocaleDirection.

[`getLocaleDirection`](/docs/platform/core/reference/gt-class-methods/locales/get-locale-direction) is a standalone utility function from General Translation's Core library that returns the text direction — left-to-right or right-to-left — for a locale. It is most often used to set the `dir` attribute of an HTML element based on the locale.

## Overview [#overview]

Import `getLocaleDirection` directly from `generaltranslation` and call it with a locale code. It does not require an API key or a [GT](/docs/platform/core/reference/gt-class/constructor) instance. For the instance-based equivalent, use the [`getLocaleDirection`](/docs/platform/core/reference/gt-class-methods/locales/get-locale-direction) method on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance instead.

```typescript
import { getLocaleDirection } from 'generaltranslation';

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

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

Signature:

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

## How it works [#how-it-works]

The function uses the `Intl.Locale` API's `textInfo.direction` property:

1. Creates an `Intl.Locale` object for the provided locale.
2. Reads the `textInfo.direction` property for the language-specific direction.
3. Returns `'rtl'` for right-to-left languages and `'ltr'` for all others.
4. Defaults to `'ltr'` if the locale is invalid or causes an error.

### RTL language recognition

Automatically detects right-to-left languages, including:

- **Arabic** (`ar`, `ar-SA`, `ar-EG`, `ar-AE`, and others)
- **Hebrew** (`he`, `he-IL`)
- **Persian/Farsi** (`fa`, `fa-IR`)
- **Urdu** (`ur`, `ur-PK`, `ur-IN`)
- **Pashto** (`ps`)
- **Sindhi** (`sd`)
- **Kurdish Sorani** (`ckb`)
- And other RTL scripts.

### Error handling

- Invalid or malformed locale codes default to `'ltr'`.
- No exceptions are thrown for invalid input.

## Parameters [#parameters]

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`locale`](#locale) | BCP-47 locale code to check text direction for. | `string` | No | — |

### `locale` [#locale]

**Type** `string` · **Required**

The BCP-47 locale code to check text direction for.

## Returns [#returns]

**Type** `'ltr' | 'rtl'`

The text direction for the locale:

- `'ltr'`: left-to-right (most languages, including English, Spanish, French, German, Chinese, and Japanese).
- `'rtl'`: right-to-left (Arabic, Hebrew, Persian, Urdu, and other Semitic/Middle Eastern languages).

## Examples [#examples]

```typescript
import { getLocaleDirection } from 'generaltranslation';

// Left-to-right languages
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"

// Right-to-left languages
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 [#notes]

- Returns `'ltr'` for all left-to-right languages (most languages worldwide).
- Returns `'rtl'` for right-to-left languages (Arabic, Hebrew, Persian, and others).
- Uses the modern `Intl.Locale` API for accurate detection.
- Works with all BCP-47 locale codes.

## Sitemap

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