Language Tag Parser

Canonicalize an ECMA-402 Unicode locale identifier and extract its language, script, region, and base name.

Description

A Unicode locale identifier identifies language and optional script, region and extensions.

A Unicode locale identifier identifies language and optional script, region and extensions. Locale syntax is separate from a user’s language preference.1, 2

Canonicalize an ECMA-402 Unicode locale identifier and extract its language, script, region, and base name.

When to use Language Tag Parser

Use this tool to canonicalize an ECMA-402 Unicode locale identifier and extract its language, script, region, and base name.

Enter the locale identifier to canonicalize and inspect using the runtime internationalization API.

How to use Language Tag Parser and understand its results

  1. Enter the locale identifier to canonicalize and inspect using the runtime internationalization API.
  2. Enter tag using the field table and calculation rules, then run the tool.
  3. Read canonical, language, script, region, baseName. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
tagUnicode locale identifier accepted by Intl.Locale.string; maximum length: 1000000Required

Enter a structurally valid tag accepted by the runtime. Return canonical tag, language, optional script/region as empty strings if absent, and baseName without extensions.

locale=new Intl.Locale(tag)

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
canonicalCanonical locale identifier.string; maximum length: 1000000
languageLanguage subtag.string; maximum length: 1000000
scriptScript subtag, empty when absent.string; maximum length: 1000000
regionRegion subtag, empty when absent.string; maximum length: 1000000
baseNameLocale identifier without extensions.string; maximum length: 1000000
json
{
  "input": {
    "tag": "zh-hant-tw-u-nu-hanidec"
  },
  "output": {
    "canonical": "zh-Hant-TW-u-nu-hanidec",
    "language": "zh",
    "script": "Hant",
    "region": "TW",
    "baseName": "zh-Hant-TW"
  }
}

Limitations and assumptions

No trimming, language detection or likely-subtag maximization is performed. Acceptance/canonical aliases follow runtime ECMA-402 data, not every possible BCP 47 form.

Numeric inputs, where present, must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use Greek Diacritic Analyzer: Count Greek accent and breathing marks after canonical Unicode decomposition. For a complementary task, use CSS Media Query Extractor: Extract lexical @media query preludes from CSS while ignoring quoted strings and comments, without evaluating conditions.

Further background: ECMA-402: Intl.Locale.

References

  1. Language Tag Parser — tool.io

  2. ECMA-402: Intl.Locale — Ecma International

Similar or alternative tools

  • Greek Diacritic Analyzer

    Count Greek accent and breathing marks after canonical Unicode decomposition.

  • CSS Media Query Extractor

    Extract lexical @media query preludes from CSS while ignoring quoted strings and comments, without evaluating conditions.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies