accept-language is a Node.js library designed to parse the HTTP Accept-Language header, enabling applications to determine the user's preferred language based on the browser's request. It adheres strictly to the BCP47 standard for language tag compliance, ensuring robust internationalization (i18n) support. The current stable version is 3.0.20, which was last updated over two years ago, indicating a mature and stable codebase with a slow release cadence focused on maintenance rather than frequent feature additions. A key differentiator of this library is its streamlined approach: it focuses on providing a single best-matched language tag from a pre-defined list, simplifying the process for common i18n use cases where a direct match is preferred over a ranked list of possibilities. This contrasts with other parsers that might return an array of parsed language objects or offer extensive, complex matching options.
npm install accept-languageVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the parser with supported languages and then use it to find the best-matching language from an HTTP Accept-Language header.
Always call `acceptLanguage.languages(yourSupportedLanguageArray)` once during application setup or before the first call to `get()`.
If using Express, install and use `express-request-language` (`npm install express-request-language`) instead of trying to integrate `accept-language` directly into your middleware stack.
Ensure all language tags (e.g., 'en-US', 'fr-CA', 'zh-Hans') adhere to BCP47 specifications for optimal performance and correct language negotiation.
Initialize the `acceptLanguage` instance with a list of supported language tags using `acceptLanguage.languages(['en-US', 'es-MX'])` before calling `get()`.
Double-check the array of language tags provided to `acceptLanguage.languages()` for correct BCP47 formatting. Also, inspect the incoming `Accept-Language` header string for any deviations from standard formatting that might hinder matching.
No dependency data recorded yet.