PrismCore / API reference / HLS playlists

Enumeration

LanguageMatch

enum LanguageMatch

Declared in Sources/PrismCore/HLS/LanguageMatch.swift · PrismCore 3.5.4

Tolerant matching of a host's preferred language against the language tags a container actually carries.

Containers are a mess about this. The same language reaches us as ISO 639-2/B (cze), 639-2/T (ces), 639-1 (cs), with a region (pt-BR), with a script (zh-Hant), uppercased, underscored (pt_BR), empty, or und. A host that asks for "cs" means all of the first three.

Foundation can answer this honestly, so there is no table here. Locale.canonicalLanguageIdentifier(from:) folds every case above — verified by probe on this toolchain (macOS 27, Swift 6): cze/CZE/Cze → cs, ger → de, alb → sq, dut → nl, pt_BR/PT-br → pt-BR, cs-cz → cs-CZ, zh-cmn-Hant → zh-Hant, and it leaves und and unknown tags alone instead of guessing.

The trap that made this comment worth writing: the obvious route, Locale.Language(identifier: "cze").languageCode?.identifier(.alpha2), returns nil — Locale.Language does not fold bibliographic codes at all, so a matcher built on it silently fails to match exactly the tags (cze, ger, fre, dut) that made tolerant matching necessary.

Type methods

static func canonical(_ tag: String?) -> String?

The canonical form of a container tag, or nil when the tag names no language.

und — the container saying it does not know — is deliberately not a language: matching it would let a host's preference land on a track whose language nobody ever claimed.

static func score(preferred: String?, candidate: String?) -> Int

How well candidate answers preferred: 2 for an exact match (including region and script), 1 for the bare language alone, 0 for no match at all.

Two levels rather than one because pt-BR and pt are both answers to "Portuguese" and only one of them is the right one — the caller takes the highest score, so an exact region match wins whenever it exists and a bare pt is still better than nothing.

Generated from the public symbols of PrismCore 3.5.4. All types