Skip to content

Commit

Permalink
Further tweaks for locale determination, fixes sidekiq#2353
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 15, 2015
1 parent edd389d commit 5e13790
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sidekiq/web_helpers.rb
Expand Up @@ -65,6 +65,7 @@ def locale
locale = 'en'.freeze
languages = request.env['HTTP_ACCEPT_LANGUAGE'.freeze] || 'en'.freeze
languages.downcase.split(','.freeze).each do |lang|
next if lang == '*'
lang = lang.split(';'.freeze)[0]
break locale = lang if find_locale_files(lang).any?
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_web_helpers.rb
Expand Up @@ -42,5 +42,11 @@ def test_locale_determination

obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
assert_equal 'zh-cn', obj.locale

obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-us; *')
assert_equal 'en', obj.locale

obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => '*')
assert_equal 'en', obj.locale
end
end

0 comments on commit 5e13790

Please sign in to comment.