cyril / accept_language.rb Goto Github PK
View Code? Open in Web Editor NEWRuby parser for Accept-Language request HTTP header ๐
Home Page: https://dev.to/cyri_/language-negotiation-with-ruby-5166
License: MIT License
Ruby parser for Accept-Language request HTTP header ๐
Home Page: https://dev.to/cyri_/language-negotiation-with-ruby-5166
License: MIT License
The required ruby version in accept_language.gemspec got bumped from 2.7.6 to 3.1.4 in commit 9a651d7 where there are mainly documentation changes and it's making it incompatible with any ruby version earlier than that.
Was it a desired change or a mistake? I really doubt it's now the minimum required version.
Here's what I'm getting if I try to update from 2.0.3 to 2.0.4 on a Rails 7 app using Ruby 3.0.6.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Could not find compatible versions
Because accept_language >= 2.0.4 depends on Ruby >= 3.1.4
and Gemfile depends on accept_language ~> 2.0.4,
Ruby >= 3.1.4 is required.
So, because current Ruby version is = 3.0.6,
version solving has failed.
Both AcceptLanguage.parse('en-us').match(*%i[de en])
and AcceptLanguage.parse('en-ca').match(*%i[de en])
return nil
while I would except them both to return :en
.
Is this a bug, or am I missing something?
string = request.headers.fetch("HTTP_ACCEPT_LANGUAGE")
locale = AcceptLanguage.parse(string).match(*I18n.available_locales)
When running the code above in my application controller I get this error: Undefined method 'match' for { :"it-it"=>1.0, :it=>0.9, :"en-us"=>0.8, :en=>0.7 }:Hash
match should be used on a string, but AcceptLanguage.parse seems like returning an hash
(I'm running the example "Rails integration example" in README)
How to reproduce:
AcceptLanguage.parse(nil)
Raise an error
/.rvm/gems/ruby-3.1.2/gems/accept_language-2.0.3/lib/accept_language/parser.rb:40:in `import': undefined method `delete' for nil:NilClass (NoMethodError)
field.delete(SPACE).split(SEPARATOR).inject({}) do |hash, lang|
I would recommend to add a casting in the parse function
def self.parse(value)
value = value.to_s
....
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.