# General Translation Platform: isValidLocale
URL: https://generaltranslation.com/en-US/docs/platform/core/reference/gt-class-methods/locales/is-valid-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Check whether a value is a valid locale code. API reference for isValidLocale.

Validates whether a locale code is properly formatted and recognized as a valid BCP-47 locale, on a [GT](/docs/platform/core/reference/gt-class/constructor) instance. General Translation checks locale structure, language recognition, and regional/script validity using the `Intl` APIs, with support for custom locale mappings.

## Overview [#overview]

Call `isValidLocale` on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance with an optional locale code. When omitted, it uses the instance's `targetLocale`.

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

console.log(gt.isValidLocale('en-US')); // true
console.log(gt.isValidLocale('invalid-locale')); // false
```

Signature:

```typescript
isValidLocale(
  locale?: string,
  customMapping?: CustomMapping
): boolean
```

*Note: `isValidLocale` runs locally using the `Intl` APIs and does not require an API key. It uses the instance's `targetLocale` and `customMapping` when those arguments are omitted. For validation without a `GT` instance, see the standalone [`isValidLocale`](/docs/platform/core/reference/utility-functions/locales/is-valid-locale).*

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

- **BCP-47 validation.** Performs comprehensive BCP-47 locale validation using the browser `Intl` APIs.
- **Custom mapping resolution.** Locales that are keys in a [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) are resolved to their canonical `code`, and that canonical code is then validated with the standard `Intl` checks — a custom-mapped locale is not automatically valid.
- **Private-use codes.** Supports private-use language codes (`qaa`–`qtz`).
- **Locale fallback.** When `locale` is omitted, the instance's `targetLocale` is used.
- **Missing locale.** Throws an `Error` if no locale is provided and the instance has no `targetLocale` configured.

## Parameters [#parameters]

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`locale`](#locale) | BCP-47 locale code to validate. | `string` | Yes | `this.targetLocale` |
| [`customMapping`](#custom-mapping) | Custom mapping to check for additional valid locales. | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | Yes | `this.customMapping` |

### `locale` [#locale]

**Type** `string` · **Optional** · **Default** `this.targetLocale`

BCP-47 locale code to validate. If not provided, uses the instance's `targetLocale`.

### `customMapping` [#custom-mapping]

**Type** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **Optional** · **Default** `this.customMapping`

Custom mapping to check for additional valid locales. If not provided, uses the instance's `customMapping`.

## Returns [#returns]

**Type** `boolean`

`true` if the locale is valid, `false` otherwise. Throws an `Error` if no locale is provided and the instance has no `targetLocale` configured.

## Examples [#examples]

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

const isValid = gt.isValidLocale('en-US');
console.log(isValid); // true

const isInvalid = gt.isValidLocale('invalid-locale');
console.log(isInvalid); // false
```

## Notes [#notes]

- Performs comprehensive BCP-47 locale validation using the browser `Intl` APIs.
- Custom mapping keys are resolved to their canonical `code`, which is then validated with the standard `Intl` checks (they are not automatically valid).
- Supports private-use language codes (`qaa`–`qtz`).
- Returns `false` for malformed or unrecognized locale codes.

## Sitemap

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