HTTP Accept-Language Parser

Parse RFC 4647 basic language ranges and HTTP quality weights while retaining header order.

Description

Accept-Language expresses preferred language ranges with optional weights.

Accept-Language expresses preferred language ranges with optional weights. The parsed sequence is a preference record rather than a selected translation.1, 2

Parse RFC 4647 basic language ranges and HTTP quality weights while retaining header order.

When to use HTTP Accept-Language Parser

Use this tool to parse RFC 4647 basic language ranges and HTTP quality weights while retaining header order.

Prepare the header field value, cookie records or status code requested. Supply field values without a header-name prefix and preserve syntax for the parser to inspect.

How to use HTTP Accept-Language Parser and understand its results

  1. Prepare the header field value, cookie records or status code requested. Supply field values without a header-name prefix and preserve syntax for the parser to inspect.
  2. Enter header using the field table and calculation rules, then run the tool.
  3. Read languages. 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
headerAccept-Language field value.string; maximum length: 1000000Required

Paste the field value. Split commas and skip empty groups; accept * or an alphabetic 1–8-character primary range with 1–8-character alphanumeric subtags. Allow only an optional q parameter, case-insensitively, from 0 to 1 with up to three decimal digits. Return ranges and weights in source order, including duplicates.

quality=explicit q or 1; output range=lowercase input range

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

Output fieldMeaningValue type
languagesLanguage ranges and their quality weights.list of object; minimum entries: 0; maximum entries: 100000
json
{
  "input": {
    "header": "en-US, de;q=0.8, *;q=0"
  },
  "output": {
    "languages": [
      {
        "range": "en-us",
        "quality": 1
      },
      {
        "range": "de",
        "quality": 0.8
      },
      {
        "range": "*",
        "quality": 0
      }
    ]
  }
}

Limitations and assumptions

No language availability, registry membership, locale fallback or content negotiation is determined. Extended wildcard ranges and extra parameters are rejected.

Numeric inputs 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 HTTP Accept Parser: Parse media ranges, parameters, and q weights in Accept without collapsing order or choosing a representation. For a complementary task, use HTTP Content-Type Parser: Parse an HTTP media type and its parameters, preserving parameter values and rejecting duplicate names.

Further background: RFC 9110: Accept-Language.

References

  1. HTTP Accept-Language Parser — tool.io

  2. RFC 9110: Accept-Language — HTTP Working Group

Similar or alternative tools

  • HTTP Accept Parser

    Parse media ranges, parameters, and q weights in Accept without collapsing order or choosing a representation.

  • HTTP Content-Type Parser

    Parse an HTTP media type and its parameters, preserving parameter values and rejecting duplicate names.

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