Skip to content

Function: parseAcceptLanguage() ​

parseAcceptLanguage(header): string[]

Read the languages of an Accept-Language header, preferred first: by decreasing quality (q, 1 when absent), then in their order in the header. The tags are normalized (normalizeLocale); the invalid ones, *, and the ones of quality 0 or an invalid quality are dropped.

Parameters ​

string | undefined

The value of the header (zh-CN,zh;q=0.9,en;q=0.8).

Returns ​

string[]

The language tags, preferred first; empty without a header.

Example ​

typescript
import {parseAcceptLanguage} from 'lakutata/com/i18n'

console.log(parseAcceptLanguage('en;q=0.5,fr,*;q=0.1')) //['fr', 'en']

Released under the MIT License.