rack-user-locale 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,9 +5,9 @@ A Rack module for getting and setting a user's locale via a cookie or browser de
5
5
 
6
6
  Credit to these gems for pointing me in the direction I wanted to go in...
7
7
 
8
- https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb
9
- https://github.com/jeremyvdw/rack-locale-selector
10
- https://github.com/jeffersongirao/rack-locale_chooser
8
+ * https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb
9
+ * https://github.com/jeremyvdw/rack-locale-selector
10
+ * https://github.com/jeffersongirao/rack-locale_chooser
11
11
 
12
12
  Installation
13
13
  ============
@@ -39,7 +39,7 @@ Your application will now attempt to set the I18n.locale value based on the foll
39
39
  * The "HTTP_ACCEPT_LANGUAGE" value
40
40
  * The I18n.default_locale value (basically a fallback)
41
41
 
42
- Should you wish to overwrite a users locale value the simple rewrite the "user-locale" cookie.
42
+ Should you wish to overwrite a users locale value then simple rewrite the "user-locale" cookie.
43
43
 
44
44
  Contributing to rack-user-locale
45
45
  =======================
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -43,16 +43,11 @@ module Rack
43
43
  accept_langs = @env["HTTP_ACCEPT_LANGUAGE"]
44
44
  return if accept_langs.nil?
45
45
 
46
- languages_and_qvalues = accept_langs.split(",").map { |l|
47
- l += ";q=1.0" unless l =~ /;q=\d+(?:\.\d+)?$/
48
- l.split(";q=")
49
- }
50
-
51
- lang = languages_and_qvalues.sort_by { |(locale, qvalue)|
52
- qvalue.to_f
53
- }.last.first
54
-
55
- lang == "*" ? nil : lang
46
+ lang = accept_langs.split(",").map { |l|
47
+ l += ';q=1.0' unless l =~ /;q=\d+\.\d+$/
48
+ l.split(';q=')
49
+ }.first
50
+ browser_locale = lang.first.split("-").first
56
51
  end
57
52
 
58
53
  def get_default_locale
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rack-user-locale"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stuart Chinery", "Dave Hrycyszyn"]
12
+ s.date = "2013-02-04"
13
+ s.description = "A Rack module for getting and setting a user's locale via a cookie or browser default language."
14
+ s.email = "stuart.chinery@headlondon.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rack-user-locale.rb",
29
+ "rack-user-locale.gemspec",
30
+ "test/helper.rb",
31
+ "test/test_rack-user-locale.rb"
32
+ ]
33
+ s.homepage = "http://github.com/sleepingstu/rack-user-locale"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.24"
37
+ s.summary = "Rack module for getting and setting a user's locale"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
44
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, [">= 0"])
46
+ s.add_development_dependency(%q<debugger>, [">= 0"])
47
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
48
+ s.add_development_dependency(%q<minitest>, [">= 0"])
49
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
50
+ s.add_development_dependency(%q<turn>, [">= 0"])
51
+ s.add_development_dependency(%q<yard>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<rack>, [">= 0"])
54
+ s.add_dependency(%q<i18n>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<debugger>, [">= 0"])
57
+ s.add_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_dependency(%q<minitest>, [">= 0"])
59
+ s.add_dependency(%q<rack-test>, [">= 0"])
60
+ s.add_dependency(%q<turn>, [">= 0"])
61
+ s.add_dependency(%q<yard>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<rack>, [">= 0"])
65
+ s.add_dependency(%q<i18n>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<debugger>, [">= 0"])
68
+ s.add_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_dependency(%q<minitest>, [">= 0"])
70
+ s.add_dependency(%q<rack-test>, [">= 0"])
71
+ s.add_dependency(%q<turn>, [">= 0"])
72
+ s.add_dependency(%q<yard>, [">= 0"])
73
+ end
74
+ end
75
+
@@ -25,21 +25,21 @@ describe "RackUserLocale" do
25
25
 
26
26
  describe "when from HTTP_ACCEPT_LANGUAGE headers" do
27
27
  before do
28
- get 'http://example.com/', {}, 'HTTP_ACCEPT_LANGUAGE' => 'ru'
28
+ get 'http://example.com/', {}, 'HTTP_ACCEPT_LANGUAGE' => 'ar-tu'
29
29
  end
30
30
 
31
- it "should have I18n.locale set to :ru" do
32
- assert_equal :ru, I18n.locale
31
+ it "should have I18n.locale set to :ar" do
32
+ assert_equal :ar, I18n.locale
33
33
  end
34
34
 
35
35
  it "should set a cookie in the response" do
36
- assert_equal "user-locale=ru; domain=example.com; path=/", last_response["Set-Cookie"]
36
+ assert_equal "user-locale=ar; domain=example.com; path=/", last_response["Set-Cookie"]
37
37
  end
38
38
  end
39
39
 
40
40
  describe "when both a cooke and HTTP_ACCEPT_LANGUAGE headers are set" do
41
41
  before do
42
- get 'http://example.com/', {}, 'HTTP_COOKIE' => 'user-locale=jp', 'HTTP_ACCEPT_LANGUAGE' => 'fr'
42
+ get 'http://example.com/', {}, 'HTTP_COOKIE' => 'user-locale=jp', 'HTTP_ACCEPT_LANGUAGE' => 'fr-be'
43
43
  end
44
44
 
45
45
  it "should have I18n.locale set to :jp" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-user-locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -174,6 +174,7 @@ files:
174
174
  - Rakefile
175
175
  - VERSION
176
176
  - lib/rack-user-locale.rb
177
+ - rack-user-locale.gemspec
177
178
  - test/helper.rb
178
179
  - test/test_rack-user-locale.rb
179
180
  homepage: http://github.com/sleepingstu/rack-user-locale
@@ -191,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  segments:
193
194
  - 0
194
- hash: 981042501419718969
195
+ hash: 3303822793188182499
195
196
  required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  none: false
197
198
  requirements: