Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BecauseOfProg/http_accept

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

HTTP::Accept

Provides parser for dealing with HTTP Accept-Language headers.

Inspired by Ruby http-accept gem

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
     http_accept:
     github: BecauseOfProg/http_accept
  2. Run shards install

Usage

require "http_accept"
# wanted_languages = HTTP::Accept::Language.parse("da, en-gb;q=0.8, en;q=0.7")
http_headers : HTTP::Headers
wanted_languages : Array(HTTP::Accept::Language::Value)? = nil
if http_headers["Accept-Language"]?
 wanted_languages = HTTP::Accept::Language.parse(http_headers["Accept-Language"])
end
HTTP::Accept::Language.best_locale(["en", "fr"], wanted_languages) # => "en"
HTTP::Accept::Language.best_locale(["fr", "nl"], wanted_languages, "fr") # => "fr"
HTTP::Accept::Language.best_locale(["en", "fr"], nil) # => "en"

TODO: Write usage instructions here

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/BecauseOfProg/http_accept/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

About

A library about parsing HTTP Accept-Language headers.

Resources

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /