Skip to content

dptole/al-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Accept-Language extra info API

Build status Issue status NPM Version Downloads Say thanks

API for reading extra information from the HTTP header Accept-Language based on the Language subtag registry file.

Details for the Accept-Language HTTP header can be found at the Tags for Identifying Languages, which refers to the Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content.

Examples

const al_api = require('@dptole/al-api')

al_api.getLanguageDescriptionBySubtag('en') // ['English']
al_api.getRegionDescriptionBySubtag('US') // ['United States']

al_api.getAcceptLanguageInfo('pt,pt-BR;q=0.9,es-VE;q=0.8')
/*
  [{
    'language': {
      'subtag': 'pt',
      'info': ['Portuguese']
    }
  }, {
    'language': {
      'subtag': 'pt',
      'info': ['Portuguese']
    },
    'region': {
      'subtag': 'BR',
      'info': ['Brazil']
    }
  }, {
    'language': {
      'subtag': 'es',
      'info': ['Castilian']
    },
    'region': {
      'subtag': 'VE',
      'info': ['Venezuela']
    }
  }]
*/

License

MIT