All files / app/i18n sorting.ts

100% Statements 9/9
100% Branches 8/8
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  96x   1x     95x   1x     94x     94x 94x     2x   96x    
function getLocalizedListSortLocales(language: string): string[] {
  if (language === "zh-Hans" || language.startsWith("zh-Hans-")) {
    // Simplified Chinese lists are conventionally sorted by romanized pinyin.
    return ["zh-Hans-u-co-pinyin", "zh-CN-u-co-pinyin", "zh-u-co-pinyin", language];
  }
 
  if (language === "zh-Hant" || language.startsWith("zh-Hant-")) {
    // Traditional Chinese lists are conventionally sorted by character strokes.
    return ["zh-Hant-u-co-stroke", "zh-TW-u-co-stroke", "zh-u-co-stroke", language];
  }
 
  return [language];
}
 
export function getLocalizedListComparer(language: string): Intl.Collator["compare"] {
  return getLocaleCollator(language).compare;
}
 
export function getLocaleCollator(language: string): Intl.Collator {
  // Intl.Collator compares strings according to locale-specific sorting rules.
  return new Intl.Collator(getLocalizedListSortLocales(language));
}