How to use the cldr-core/supplemental/likelySubtags.json.supplemental function in cldr-core

To help you get started, we’ve selected a few cldr-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / testpilot / frontend / src / app / containers / App / index.js View on Github external
langs[lang] = `${langs[lang] || ""}${data}
`;
        });
      }
      return Promise.resolve();
    }

    const availableLanguages = document.querySelector(
      "meta[name=availableLanguages]").content.split(",");

    const negotiated = negotiateLanguages(
      navigator.languages,
      availableLanguages,
      {
        defaultLocale: "en-US",
        likelySubtags: likelySubtagsData.supplemental.likelySubtags
      }
    );

    this.props.setNegotiatedLanguages(negotiated);

    const promises = negotiated.map(language =>
      Promise.all(
        [
          fetch(`/static/locales/${language}/app.ftl`).then(response => addLang(language, response)),
          fetch(`/static/locales/${language}/experiments.ftl`).then(response => addLang(language, response))
        ]
      )
    );

    Promise.all(promises).then(() => {
      this.props.setLocalizations(langs);
github mozilla / send / server / middleware / language.js View on Github external
return next();
  }
  const langs = header.replace(/\s/g, '').match(acceptLanguages) || ['en-US'];
  const preferred = langs
    .map(l => {
      const parts = l.split(';');
      return {
        locale: parts[0],
        q: parts[1] ? parseFloat(parts[1].split('=')[1]) : 1
      };
    })
    .sort((a, b) => b.q - a.q)
    .map(x => x.locale);
  req.language = negotiateLanguages(preferred, languages, {
    strategy: 'lookup',
    likelySubtags: langData.supplemental.likelySubtags,
    defaultLocale: 'en-US'
  })[0];
  next();
};