Skip to main content

best_match

Function best_match 

Source
pub fn best_match(
    preferred: &[LangCode],
    offered: &[LangCode],
) -> Option<LangCode>
Expand description

The offered language that fits the system’s: preferred is the system’s languages, most preferred first, and offered the source’s tag and the packs’. For each preferred tag in order:

  1. the tag, then each of its parents, if offered (en-GB matches an en source);
  2. Chinese without a script takes one from its region (CN and SG give Hans; TW, HK and MO give Hant), then step 1 again with the script written after the language (zh-CN matches zh-Hans, through zh-Hans-CN);
  3. the only offered tag with the same language subtag, unless both have a script (written, or from step 2) and they differ (pt-PT matches a lone pt-BR; zh-TW doesn’t match zh-Hans).

The first preferred tag that matches wins. None if none does: the caller then uses the source. No CLDR data: no likely subtags beyond step 2’s five regions, no aliases, and no parent but the shorter tag.