Edit Page

req.acceptsLanguages()

Return whether this request (req) advertises that it understands any of the specified language(s), and if so, which one.

If more than one of the languages passed in to this method are considered acceptable, then the first one will be returned. If none of the languages are considered acceptable, this returns false. (By languages, we mean natural languages, like English or Japanese, not programming languages.)

Usage

#
req.acceptsLanguages(language);

Or:

Details

#

This method can be useful as a complement to built-in internationalization and localization, which allows for automatically serving different content to different locales based on the request.

Example

#

If a request is sent with "Accept-Language: da, en, en-gb, en-us;":

req.acceptsLanguages('en');
// -> 'en'

req.acceptsLanguages('es');
// -> false

req.acceptsLanguages('en-us', 'en', 'en-gb');
// -> 'en-us'

req.acceptsLanguages('en-gb', 'en', 'en-us');
// -> 'en-gb'

req.acceptsLanguages('es', 'fr');
// -> false

Notes

#
  • You can expect the "Accept-Language" header to exist in most requests that originate in web browsers (see RFC-2616).
  • Browsers send the "Accept-Language" header automatically, based on the user's language settings.
  • See the accepts package for the finer details of the header-parsing algorithm used in Sails/Express.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference