How to use @fluent/langneg - 2 common examples

To help you get started, we’ve selected a few @fluent/langneg 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 / send / server / middleware / language.js View on Github external
if (header.length > 255) {
    req.language = 'en-US';
    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();
};
github projectfluent / fluent-web / src / index.js View on Github external
async function* generateMessages(resourceIds) {
  const locales = negotiateLanguages(
    navigator.languages,
    meta.available,
    {
      defaultLocale: meta.default,
    },
  );
  for (const locale of locales) {
    yield createContext(locale, resourceIds);
  }
}

@fluent/langneg

Language Negotiation API for Fluent

Apache-2.0
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Popular @fluent/langneg functions