# Locale

> The Locale is a set of language and regional settings, identified by a code like `en-US` or `pt-BR`.

## What is a locale code?

The identifier of a language and optionally a region and script, such as 'en-US', 'en-GB' or 'zh-Hant'. It defines how texts, dates, numbers, currencies and sorting look. Codes follow the BCP 47 standard.

- Topic: Internationalization
- Type: concept

## Example

Wrong:

```js
const format = new Intl.NumberFormat('en_US');
format.format(1234.5);
```

Right:

```js
const format = new Intl.NumberFormat('en-US');
format.format(1234.5);
```

BCP 47 tags use hyphens; an underscore like 'en_US' makes `Intl` throw a `RangeError`.

## Common mistakes

- Using a country flag to represent a language.

## Key points

- Locale codes use BCP 47 format with a hyphen, for example 'pt-BR', not 'pt_BR'.
- The app falls back to a base language when a regional variant is missing.

## Interview questions

### How do I get the user's locale in JavaScript?

Read `navigator.language` for the top preference or `navigator.languages` for the full list, and let the user override it in settings.

### What is the difference between 'en-US' and 'en-GB'?

Same language, different region: they differ in spelling, date order, units and currency, for example '3/4' versus '04/03' for the same date.

### Is a locale the same as a language?

No. A locale adds region and sometimes script to a language, so 'pt-BR' and 'pt-PT' share a language but differ in words and formats.

## Related cards

- [Intl.Locale](https://wonderium.dev/js/intl-locale.md)
- [\[lang\]](https://wonderium.dev/html/lang.md)
- [Accept-Language](https://wonderium.dev/web/accept-language.md)
- [CLDR](https://wonderium.dev/web/cldr.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/locale
- Last updated: 2026-11-25
