• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / dec99f3d-a866-4bcf-8251-ee3e652521e0

05 Feb 2025 07:28PM CUT coverage: 85.083% (-0.009%) from 85.092%
dec99f3d-a866-4bcf-8251-ee3e652521e0

push

circleci

web-flow
Merge pull request #5356 from mozilla/dependabot/pip/black-25.1.0

Bump black from 24.10.0 to 25.1.0

2433 of 3561 branches covered (68.32%)

Branch coverage included in aggregate %.

17000 of 19279 relevant lines covered (88.18%)

9.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/frontend/src/components/waitlist/LocalePicker.tsx
1
import { SelectHTMLAttributes, useEffect, useState } from "react";
×
2
import { getLocale } from "../../functions/getLocale";
×
3
import { useL10n } from "../../hooks/l10n";
×
4

5
type LocaleDisplayNames = Record<string, string>;
6
type Languages = {
7
  main: Record<
8
    string,
9
    {
10
      localeDisplayNames: {
11
        languages: LocaleDisplayNames;
12
      };
13
    }
14
  >;
15
};
16
export type Props = SelectHTMLAttributes<HTMLSelectElement> & {
17
  supportedLocales: string[];
18
};
19
export const LocalePicker = ({ supportedLocales, ...selectProps }: Props) => {
×
20
  const l10n = useL10n();
×
21
  const currentLocale = getLocale(l10n);
×
22
  const [localeDisplayNames, setLocaleDisplayNames] =
23
    useState<LocaleDisplayNames>();
×
24

25
  useEffect(() => {
×
26
    importLanguages(currentLocale).then((localeDisplayNames) => {
×
27
      setLocaleDisplayNames(localeDisplayNames);
×
28
    });
29
  }, [currentLocale]);
30

31
  const options = Object.entries(localeDisplayNames ?? {})
×
32
    .sort(([_codeA, nameA], [_codeB, nameB]) => nameA.localeCompare(nameB))
×
33
    .filter(([code]) => supportedLocales.includes(code))
×
34
    .map(([code, name]) => (
35
      <option key={code} value={code}>
×
36
        {name}
37
      </option>
38
    ));
39

40
  return <select {...selectProps}>{options}</select>;
41
};
42

43
async function importLanguages(locale: string): Promise<LocaleDisplayNames> {
44
  try {
×
45
    const languages: Languages = await import(
×
46
      `cldr-localenames-modern/main/${locale}/languages.json`
×
47
    );
48
    return languages.main[locale].localeDisplayNames.languages;
×
49
  } catch (_e) {
50
    try {
×
51
      // cldr-localenames-modern doesn't include suffixed locale codes for
52
      // locales in their main territory (i.e. it only has `es`, not `es-ES`, or
53
      // `nl` but not `nl-NL`, or `sv` but not `sv-SE`), so try loading a
54
      // truncated version if the full version was not found:
55
      const truncatedLocale = locale.split("-")[0];
×
56
      const languages: Languages = await import(
×
57
        `cldr-localenames-modern/main/${truncatedLocale}/languages.json`
×
58
      );
59
      return languages.main[truncatedLocale].localeDisplayNames.languages;
×
60
    } catch (_e) {
61
      const languagesEn = await import(
×
62
        "cldr-localenames-modern/main/en/languages.json"
63
      );
64
      return languagesEn.main.en.localeDisplayNames.languages;
×
65
    }
66
  }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc