Parse any language tag — zh-Hant-HK, en-GB-oxendict, de-CH-1901-x-phonebk, i-navajo — into the parts RFC 5646 defines (language, extlang, script, region, variants, extensions, private-use). Validates per-subtag shape, canonicalizes deprecated codes (iw→he, zh-yue→yue), emits the RFC 4647 fallback chain, and runs Basic / Extended Filtering and Lookup against an Accept-Language header so you can debug why your locale switcher picked the wrong one.
The Lookup algorithm removes subtags from the right until a match is found. Single-character extension singletons and their subtags are removed as a group.
i-navajo, i-klingon, zh-min-nan, …) are legal but should be replaced with their preferred value from the IANA registry when authoring new content.zh-cmn, ar-arb) are legal but the current recommendation is to use the primary subtag alone (cmn, arb) when the language is known.419 = Latin America and the Caribbean, 001 = World). 2-letter codes are ISO 3166-1 alpha-2.x ends the tag — everything after it is opaque to the outside world.