HTTP::Accept
Provides parser for dealing with HTTP Accept-Language
headers.
Inspired by Ruby http-accept gem
Installation
-
Add the dependency to your
shard.yml
:dependencies: http_accept: github: BecauseOfProg/http_accept
-
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
- Fork it (https://github.com/BecauseOfProg/http_accept/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Nicolas Martinussen - creator and maintainer