Locale
A combination of language / region / formatting settings. It is represented by identifiers such as ja-JP (Japanese / Japan) and en-US (English / United States).
A locale is an identifier that represents a combination of language / region / formatting settings. The typical form joins a language code and a region code, as in ja-JP (Japanese / Japan), en-US (English / United States), and zh-CN (Chinese / China), where the language code comes from ISO 639 and the region code comes from ISO 3166-1. Because notation rules differ by region even within the same language (for example, en-US and en-GB differ in date format and spelling), the region code matters as well as the language code.
However, the structure of the identifier is not limited to the two elements "language + region." Language tags standardized as BCP 47 are structured so that subtags for language / script / region / variant are arranged in this order, and extensions that add finer specifications such as calendars and time notation can be attached after them. Chinese is the typical example where the script subtag is indispensable, with Simplified Chinese written as zh-Hans and Traditional Chinese as zh-Hant (script codes come from ISO 15924). Because regions and scripts do not correspond one-to-one, as with Singapore, which uses Simplified Chinese, and Hong Kong, which uses Traditional Chinese, building with only the two choices zh-CN and zh-TW leaves gaps. Japanese also has a form that includes the script, such as ja-Jpan-JP, but for languages whose script is effectively fixed to one, it is customary to omit it.
Locales affect every aspect of text display, including date formats (2025/01/15 vs 01/15/2025 vs 15.01.2025), number formats (1,000.50 vs 1.000,50), currency symbols (¥ vs $ vs €), sort order, and text direction (LTR/RTL). For example, the German locale (de-DE) uses a comma for the decimal point and a period for the thousands separator, so "1.000" means one thousand. Ignoring this difference causes serious bugs in the display of amounts and quantities.
In JavaScript, the Intl object provides locale-aware formatting. Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }) gives a Japanese-style currency format such as "¥1,000". The yen sign added here is the full-width ¥ (U+FFE5), which is a different character from the half-width ¥ (U+00A5) used when the same JPY is formatted with en-US. Because they look similar, the difference is hard to notice, but it shows up in display width calculations and in counters that count full-width characters as 2 characters. If you manage the upper limit in bytes, the difference that the full-width yen sign is 3 bytes and the half-width one is 2 bytes in UTF-8 also comes into play. Intl.DateTimeFormat, Intl.Collator, Intl.PluralRules, and others are also available, enabling locale-dependent date display, string sorting, and plural handling.
In multilingual support for websites, a common mechanism is to detect the user's browser locale (navigator.language) and display the appropriate language version. However, because there are cases where the browser's locale setting does not match the user's preferred language, you should always provide a language switching UI. Web standards related to locales are wide-ranging, including the HTML lang attribute, the hreflang tag, and the Accept-Language header.
A common misconception is confusing locales with character encodings. A locale defines rules for display formats, and it is a separate concept from the character encoding scheme (UTF-8, Shift_JIS, and so on). Also, switching the locale does not rewrite the stored text data itself. What changes is how that data is displayed. However, there are exceptions when you include processing that transforms strings. Uppercase / lowercase conversion depends on the locale: passing "istanbul" to JavaScript's toLocaleUpperCase gives "ISTANBUL" in the default locale, whereas specifying Turkish (tr) uses the dotted capital İ (U+0130) and gives "İSTANBUL". This is because in Turkish and Azerbaijani the correspondence between i and I differs from other languages, and it becomes a source of bugs with real consequences in code that compares converted strings or uses them as search keys. For case-insensitive comparisons, it is safe to avoid locale-dependent conversion and use the locale-independent toLowerCase, or to compare with the sensitivity option of Intl.Collator.
From a character counting perspective, the number of characters needed to express the same information varies greatly by locale. For example, when the same date, January 15, 2025, is formatted in the long form of Intl.DateTimeFormat, Japanese (ja-JP) gives the 10 characters of 2025年1月15日, English (en-US) gives the 16 characters of January 15, 2025, and German (de-DE) gives the 15 characters of 15. Januar 2025. Japanese is the shortest because the year, month, and day are each written with a single kanji, and no separating spaces are inserted. However, being short is a matter of character count, and because of the full-width characters, the display width does not shrink as much as the ratio of character counts. Note that in Japanese text there is also a notation that inserts half-width spaces before and after numbers for readability, in which case the same date becomes 15 characters. This is a good example of how the result changes depending on whether what you count is program output or text written by a person. When designing UI elements with character limits (buttons, labels, and so on) on a multilingual site, you need to take into account the differences in character count by locale.