Giter VIP home page Giter VIP logo

accept_language.rb's People

Contributors

cyril avatar petergoldstein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

accept_language.rb's Issues

Can't upgrade gem to 2.0.4 on Ruby 3.0.6. Required Ruby version got bumped from 2.7.6 to 3.1.4 by mistake?

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.

Undefined method 'match' for Hash

Code:

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)

Parse cannot accept nil value

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.