rack-user-locale 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -1
- data/VERSION +1 -1
- data/lib/rack-user-locale.rb +1 -10
- data/rack-user-locale.gemspec +1 -1
- data/test/test_rack-user-locale.rb +0 -56
- metadata +2 -2
data/README.md
CHANGED
@@ -49,9 +49,23 @@ use Rack::UserLocale, :accepted_locales => [:de, :en, :es, :fr, :ja, :pt, :zh, (
|
|
49
49
|
|
50
50
|
If this option is supplied the the users locale will either be set to one of the accepted locales in the array, otherwise it will be set to the I18n.default_locale value.
|
51
51
|
|
52
|
-
|
53
52
|
Should you wish to overwrite a users locale value at any point in your application, like for changing language prefs, then simple rewrite the "user-locale" cookie with a new value.
|
54
53
|
|
54
|
+
**Note:**
|
55
|
+
|
56
|
+
The user locale detection is done on every Rack::Request, which would include all of the non Ruby/Rack actions like .css or .js files.
|
57
|
+
|
58
|
+
If you don't want this happen then you can use Rack::Static in your application and filter out which files Rack should serve up statically.
|
59
|
+
|
60
|
+
Something like this:
|
61
|
+
|
62
|
+
```
|
63
|
+
use Rack::Static, :urls => ["/*"], :root => "public"
|
64
|
+
```
|
65
|
+
would serve anything in your public folder statically and wouldn't create a Rack::Request.
|
66
|
+
|
67
|
+
See the [Rack::Static docs](http://rack.rubyforge.org/doc/classes/Rack/Static.html) for more info.
|
68
|
+
|
55
69
|
Contributing to rack-user-locale
|
56
70
|
=======================
|
57
71
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/rack-user-locale.rb
CHANGED
@@ -9,21 +9,12 @@ module Rack
|
|
9
9
|
}.merge(options)
|
10
10
|
end
|
11
11
|
|
12
|
-
# The "non_ruby_request" variable denotes a request which doesn't call a Ruby script.
|
13
|
-
# This might be a CSS, static HTML, image, media, or JavaScript request.
|
14
|
-
#
|
15
|
-
# This check is in place so that if you're using this gem with multiple Rack
|
16
|
-
# apps running in the same application context, you won't have static resources
|
17
|
-
# resetting the currency selection due to requests going into the main app
|
18
|
-
# instead of a sub-app.
|
19
|
-
#
|
20
12
|
def call(env)
|
21
13
|
@env = env
|
22
14
|
@request = Rack::Request.new(@env)
|
23
15
|
set_locale
|
24
16
|
|
25
|
-
|
26
|
-
if @request.post? || @request.put? || @request.delete? || non_ruby_request
|
17
|
+
if @request.post? || @request.put? || @request.delete?
|
27
18
|
@app.call(env)
|
28
19
|
else
|
29
20
|
status, headers, body = @app.call(@env)
|
data/rack-user-locale.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rack-user-locale"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Stuart Chinery", "Dave Hrycyszyn"]
|
@@ -92,34 +92,6 @@ describe "RackUserLocale" do
|
|
92
92
|
assert_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
96
|
-
describe "when SCRIPT_NAME is nil" do
|
97
|
-
before do
|
98
|
-
get "http://example.com/", {}
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should have I18n.locale set to :en" do
|
102
|
-
assert_equal :en, I18n.locale
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should set a cookie in the response" do
|
106
|
-
refute_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "when SCRIPT_NAME is blank" do
|
111
|
-
before do
|
112
|
-
get "http://example.com/", {}, { "SCRIPT_NAME" => "" }
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should have I18n.locale set to :en" do
|
116
|
-
assert_equal :en, I18n.locale
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should set a cookie in the response" do
|
120
|
-
refute_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
121
|
-
end
|
122
|
-
end
|
123
95
|
end
|
124
96
|
|
125
97
|
describe "with accepted_locales set" do
|
@@ -244,33 +216,5 @@ describe "RackUserLocale" do
|
|
244
216
|
assert_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
245
217
|
end
|
246
218
|
end
|
247
|
-
|
248
|
-
describe "when SCRIPT_NAME is nil" do
|
249
|
-
before do
|
250
|
-
get "http://example.com/", {}
|
251
|
-
end
|
252
|
-
|
253
|
-
it "should have I18n.locale set to :en" do
|
254
|
-
assert_equal :en, I18n.locale
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should set a cookie in the response" do
|
258
|
-
refute_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
describe "when SCRIPT_NAME is blank" do
|
263
|
-
before do
|
264
|
-
get "http://example.com/", {}, { "SCRIPT_NAME" => "" }
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should have I18n.locale set to :en" do
|
268
|
-
assert_equal :en, I18n.locale
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should set a cookie in the response" do
|
272
|
-
refute_equal "user-locale=en; domain=example.com; path=/", last_response["Set-Cookie"]
|
273
|
-
end
|
274
|
-
end
|
275
219
|
end
|
276
220
|
end
|
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.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
segments:
|
193
193
|
- 0
|
194
|
-
hash: -
|
194
|
+
hash: -2671842135263773507
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
none: false
|
197
197
|
requirements:
|