How to use the negotiator/lib/language.preferredLanguages function in negotiator

To help you get started, we’ve selected a few negotiator 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 adonisjs / adonis-antl / middleware / Antl.js View on Github external
_getViaQueryString (definedLocales, allowedLocales) {
    if (typeof (definedLocales) === 'string' && definedLocales.length) {
      const detectedLocale = preferredLanguages(definedLocales, allowedLocales)
      return detectedLocale instanceof Array ? detectedLocale[0] : detectedLocale
    }
    return null
  }
github Feverqwe / Mono / mono / localeMixin.js View on Github external
getLocale() {
    let availableLanguages = [];
    if (Array.isArray(navigator.languages)) {
      availableLanguages = navigator.languages;
    } else
    if (navigator.language) {
      availableLanguages = [navigator.language];
    }
    const languages = preferredLanguages(availableLanguages.join(','), Object.keys(this.localeMap));
    let locale = this.localeMap[this.defaultLocale];
    if (languages) {
      locale = Object.assign({}, locale, this.localeMap[languages[0]]);
    }
    return locale;
  }
};

negotiator

HTTP content negotiation

MIT
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis