# Locale

> Locale with language, region, script, text direction, and display names.

- Name: `locale`
- Categories: i18n
- Detail page: https://open-types.dev/types/locale

## Install

```bash
# Types only
npx shadcn add @open-types/locale

# Types + Zod v4 validators
npx shadcn add @open-types/locale-zod

# Types + real-world examples
npx shadcn add @open-types/locale-examples
```

## Types

```typescript
export type TextDirection = "ltr" | "rtl";

export interface Locale {
  code: string;
  language: string;
  region?: string;
  script?: string;
  direction?: TextDirection;
  name: string;
  native_name?: string;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { Locale, TextDirection } from "../types/locale";

export const textDirectionSchema = z.enum(["ltr", "rtl"]) satisfies z.ZodType<TextDirection>;

export const localeSchema = z.object({
  code: z.string().min(1, { error: "Locale code is required" }),
  language: z.string().min(1, { error: "Language is required" }),
  region: z.string().min(1, { error: "Region cannot be empty" }).optional(),
  script: z.string().min(1, { error: "Script cannot be empty" }).optional(),
  direction: textDirectionSchema.optional(),
  name: z.string().min(1, { error: "Name is required" }),
  native_name: z.string().min(1, { error: "Native name cannot be empty" }).optional(),
}) satisfies z.ZodType<Locale>;

export type { Locale, TextDirection } from "../types/locale";
```

## Examples

```typescript
// Source: hand-crafted; based on BCP-47 tags
import type { Locale, TextDirection } from "../types/locale";

export const textDirectionExamples = {
  ltr: "ltr",
  rtl: "rtl",
} as const satisfies Record<string, TextDirection>;

export const localeExamples = {
  enUS: {
    code: "en-US",
    language: "en",
    region: "US",
    direction: "ltr",
    name: "English (United States)",
    native_name: "English (United States)",
  } satisfies Locale,
  esES: {
    code: "es-ES",
    language: "es",
    region: "ES",
    direction: "ltr",
    name: "Spanish (Spain)",
    native_name: "Español (España)",
  } satisfies Locale,
  arSA: {
    code: "ar-SA",
    language: "ar",
    region: "SA",
    direction: "rtl",
    name: "Arabic (Saudi Arabia)",
    native_name: "العربية (المملكة العربية السعودية)",
  } satisfies Locale,
  heIL: {
    code: "he-IL",
    language: "he",
    region: "IL",
    direction: "rtl",
    name: "Hebrew (Israel)",
    native_name: "עברית (ישראל)",
  } satisfies Locale,
  zhHansCN: {
    code: "zh-Hans-CN",
    language: "zh",
    script: "Hans",
    region: "CN",
    direction: "ltr",
    name: "Chinese (Simplified, China)",
    native_name: "中文（简体，中国）",
  } satisfies Locale,
  enLanguageOnly: {
    code: "en",
    language: "en",
    name: "English",
  } satisfies Locale,
} as const;
```
