BCP 47 language tag
The standard tag behind values like en, en-GB, and zh-Hant-TW, combining a language with optional script, region, and variants.
What it is
A BCP 47 language tag is the standard label for a language and any useful refinements. Only the language subtag is required, as in 'en'. A script, region, and variants can follow, producing tags such as 'sr-Latn-RS' or 'sl-rozaj'. RFC 5646 defines the syntax and the IANA Language Subtag Registry supplies the registered pieces.
Use the tag as the one locale identifier passed through routing, HTML's lang attribute, translation catalogs, and Intl APIs. Tags are case-insensitive, but the readable convention is lowercase language, title-case script, and uppercase region. Use Intl.getCanonicalLocales or Intl.Locale to canonicalize input instead of hand-splitting it.
Gotcha: the separator is a hyphen, not an underscore. POSIX and Java write 'pt_BR', the web writes 'pt-BR', and a mapping layer between them is usually where locale bugs hide. Every extra subtag should express a real distinction your product supports. A tag does not encode a time zone, currency, or nationality. It also does not mean every possible combination has translations available, so match it against the catalog locales you actually ship.
Ask AI for it
Normalize locale input as BCP 47 tags with Intl.getCanonicalLocales. Reject values that throw a RangeError, then construct Intl.Locale objects and expose their language, script, and region fields without assuming script or region is present. Use the canonical hyphenated tag for the HTML lang attribute, route segment, and message-catalog lookup. Match only against the app's explicit supported-locale list, and keep currency and time zone in separate settings.