rails_locale_detection 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -6
- data/Gemfile.lock +35 -32
- data/README.md +75 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/rails/locale_detection.rb +7 -2
- data/rails_locale_detection.gemspec +20 -23
- data/spec/rails_locale_detection_spec.rb +113 -5
- metadata +129 -150
- data/README.rdoc +0 -63
data/Gemfile
CHANGED
@@ -9,10 +9,9 @@ gem 'http_accept_language'
|
|
9
9
|
group :development do
|
10
10
|
gem 'i18n'
|
11
11
|
gem 'timecop'
|
12
|
-
gem 'actionpack', '~> 3.2.
|
13
|
-
gem 'activesupport', '~> 3.2.
|
14
|
-
gem "rspec", "~> 2.
|
15
|
-
gem "bundler", "~> 1.
|
16
|
-
gem "jeweler", "~> 1.
|
17
|
-
gem "rcov", ">= 0"
|
12
|
+
gem 'actionpack', '~> 3.2.9'
|
13
|
+
gem 'activesupport', '~> 3.2.9'
|
14
|
+
gem "rspec", "~> 2.12.0"
|
15
|
+
gem "bundler", "~> 1.2.3"
|
16
|
+
gem "jeweler", "~> 1.8.4"
|
18
17
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,67 +1,70 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionpack (3.2.
|
5
|
-
activemodel (= 3.2.
|
6
|
-
activesupport (= 3.2.
|
4
|
+
actionpack (3.2.9)
|
5
|
+
activemodel (= 3.2.9)
|
6
|
+
activesupport (= 3.2.9)
|
7
7
|
builder (~> 3.0.0)
|
8
8
|
erubis (~> 2.7.0)
|
9
|
-
journey (~> 1.0.
|
9
|
+
journey (~> 1.0.4)
|
10
10
|
rack (~> 1.4.0)
|
11
11
|
rack-cache (~> 1.2)
|
12
12
|
rack-test (~> 0.6.1)
|
13
|
-
sprockets (~> 2.1
|
14
|
-
activemodel (3.2.
|
15
|
-
activesupport (= 3.2.
|
13
|
+
sprockets (~> 2.2.1)
|
14
|
+
activemodel (3.2.9)
|
15
|
+
activesupport (= 3.2.9)
|
16
16
|
builder (~> 3.0.0)
|
17
|
-
activesupport (3.2.
|
17
|
+
activesupport (3.2.9)
|
18
18
|
i18n (~> 0.6)
|
19
19
|
multi_json (~> 1.0)
|
20
|
-
builder (3.0.
|
20
|
+
builder (3.0.4)
|
21
21
|
diff-lcs (1.1.3)
|
22
22
|
erubis (2.7.0)
|
23
23
|
git (1.2.5)
|
24
24
|
hike (1.2.1)
|
25
25
|
http_accept_language (1.0.2)
|
26
|
-
i18n (0.6.
|
27
|
-
jeweler (1.
|
26
|
+
i18n (0.6.1)
|
27
|
+
jeweler (1.8.4)
|
28
28
|
bundler (~> 1.0)
|
29
29
|
git (>= 1.2.5)
|
30
30
|
rake
|
31
|
-
|
32
|
-
|
31
|
+
rdoc
|
32
|
+
journey (1.0.4)
|
33
|
+
json (1.7.5)
|
34
|
+
multi_json (1.5.0)
|
33
35
|
rack (1.4.1)
|
34
36
|
rack-cache (1.2)
|
35
37
|
rack (>= 0.4)
|
36
|
-
rack-test (0.6.
|
38
|
+
rack-test (0.6.2)
|
37
39
|
rack (>= 1.0)
|
38
|
-
rake (0.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rspec-
|
43
|
-
rspec-
|
44
|
-
|
45
|
-
rspec-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
rake (10.0.3)
|
41
|
+
rdoc (3.12)
|
42
|
+
json (~> 1.4)
|
43
|
+
rspec (2.12.0)
|
44
|
+
rspec-core (~> 2.12.0)
|
45
|
+
rspec-expectations (~> 2.12.0)
|
46
|
+
rspec-mocks (~> 2.12.0)
|
47
|
+
rspec-core (2.12.2)
|
48
|
+
rspec-expectations (2.12.1)
|
49
|
+
diff-lcs (~> 1.1.3)
|
50
|
+
rspec-mocks (2.12.1)
|
51
|
+
sprockets (2.2.2)
|
49
52
|
hike (~> 1.2)
|
53
|
+
multi_json (~> 1.0)
|
50
54
|
rack (~> 1.0)
|
51
55
|
tilt (~> 1.1, != 1.3.0)
|
52
56
|
tilt (1.3.3)
|
53
|
-
timecop (0.
|
57
|
+
timecop (0.5.5)
|
54
58
|
|
55
59
|
PLATFORMS
|
56
60
|
ruby
|
57
61
|
|
58
62
|
DEPENDENCIES
|
59
|
-
actionpack (~> 3.2.
|
60
|
-
activesupport (~> 3.2.
|
61
|
-
bundler (~> 1.
|
63
|
+
actionpack (~> 3.2.9)
|
64
|
+
activesupport (~> 3.2.9)
|
65
|
+
bundler (~> 1.2.3)
|
62
66
|
http_accept_language
|
63
67
|
i18n
|
64
|
-
jeweler (~> 1.
|
65
|
-
|
66
|
-
rspec (~> 2.3.0)
|
68
|
+
jeweler (~> 1.8.4)
|
69
|
+
rspec (~> 2.12.0)
|
67
70
|
timecop
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# rails_locale_detection
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/mateomurphy/rails_locale_detection.png?branch=master)](https://travis-ci.org/mateomurphy/rails_locale_detection)
|
4
|
+
[![Dependency Status](https://gemnasium.com/mateomurphy/rails_locale_detection.png)](https://gemnasium.com/mateomurphy/rails_locale_detection)
|
5
|
+
|
6
|
+
Sets the current locale of a request using a combination of params, cookies, http headers, and an optional user object.
|
7
|
+
|
8
|
+
In turn, it checks the value of params[:locale], cookies[:locale] and HTTP_ACCEPT_LANGUAGE headers to find a locale that
|
9
|
+
corresponds to the available locales, then stores the set locale in a cookie for future requests. If a user_locale method
|
10
|
+
is provided, the return value will be used, with preference over the other locale detection methods.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Include the gem in your Gemfile
|
15
|
+
|
16
|
+
gem 'rails_locale_detection'
|
17
|
+
|
18
|
+
Set your default and available locales
|
19
|
+
|
20
|
+
I18n.default_locale = :en
|
21
|
+
I18n.available_locales = [:en, :fr]
|
22
|
+
|
23
|
+
Call `set_locale` as a filter in your controllers
|
24
|
+
|
25
|
+
class ApplicationController < ActionController::Base
|
26
|
+
before_filter :set_locale
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
To support user locales, add a `user_locale` method
|
31
|
+
|
32
|
+
class ApplicationController < ActionController::Base
|
33
|
+
before_filter :set_locale
|
34
|
+
|
35
|
+
def user_locale
|
36
|
+
current_user.locale if current_user
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
## Configuration
|
43
|
+
|
44
|
+
Configuration is done via a block that can be added as an initializer:
|
45
|
+
|
46
|
+
Rails::LocaleDetection.config do |config|
|
47
|
+
config.locale_expiry = 3.months
|
48
|
+
config.set_default_url_option = :always # valid values are true, false, :always, :never and :explicity
|
49
|
+
config.detection_order = [:user, :param, :cookie, :request]
|
50
|
+
end
|
51
|
+
|
52
|
+
The configuration options:
|
53
|
+
|
54
|
+
* `locale_expiry` sets how long the locale cookie lasts.
|
55
|
+
* `set_default_url_option` determines under which conditions the `default_url_option` is set
|
56
|
+
* `true` or `:always` sets the option on all requests
|
57
|
+
* `false` or `:never` never sets the option
|
58
|
+
* `:explicity` sets the option only when a param[:locale] is present
|
59
|
+
* `detection_order` set the order in which locale detection occurs. Omit values to skip those sources
|
60
|
+
|
61
|
+
## Contributing to rails_locale_detection
|
62
|
+
|
63
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
64
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
65
|
+
* Fork the project
|
66
|
+
* Start a feature/bugfix branch
|
67
|
+
* Commit and push until you are happy with your contribution
|
68
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
69
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
70
|
+
|
71
|
+
## Copyright
|
72
|
+
|
73
|
+
Copyright (c) 2012 Mateo Murphy. See LICENSE.txt for
|
74
|
+
further details.
|
75
|
+
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
@@ -4,7 +4,7 @@ module Rails
|
|
4
4
|
@@locale_expiry = 3.months
|
5
5
|
|
6
6
|
mattr_accessor :set_default_url_option
|
7
|
-
@@set_default_url_option =
|
7
|
+
@@set_default_url_option = :always
|
8
8
|
|
9
9
|
mattr_accessor :detection_order
|
10
10
|
@@detection_order = [:user, :param, :cookie, :request]
|
@@ -54,12 +54,17 @@ module Rails
|
|
54
54
|
detection_order.inject(nil) { |result, source| result || locale_from(source) } || default_locale
|
55
55
|
end
|
56
56
|
|
57
|
+
# returns true if the default url option should be set for this request
|
58
|
+
def set_default_url_option_for_request?
|
59
|
+
set_default_url_option === true || set_default_url_option == :always || set_default_url_option == :explicitly && params[:locale].present?
|
60
|
+
end
|
61
|
+
|
57
62
|
# set I18n.locale, default_url_options[:locale] and cookies[:locale] to the value returned by
|
58
63
|
# get_locale
|
59
64
|
def set_locale
|
60
65
|
I18n.locale = get_locale
|
61
66
|
|
62
|
-
default_url_options[:locale] = I18n.locale if
|
67
|
+
default_url_options[:locale] = I18n.locale if set_default_url_option_for_request?
|
63
68
|
|
64
69
|
cookies[:locale] = { :value => I18n.locale, :expires => locale_expiry.from_now }
|
65
70
|
|
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rails_locale_detection"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mateo Murphy"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-12-24"
|
13
13
|
s.description = "Sets the current locale of a request using a combination of params, cookies, and http headers"
|
14
14
|
s.email = "mateo.murphy@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
24
|
"LICENSE.txt",
|
25
|
-
"README.
|
25
|
+
"README.md",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"lib/rails/locale_detection.rb",
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = "http://github.com/mateomurphy/rails_locale_detection"
|
36
36
|
s.licenses = ["MIT"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.23"
|
39
39
|
s.summary = "locale setting for rails project"
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
@@ -45,33 +45,30 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.add_runtime_dependency(%q<http_accept_language>, [">= 0"])
|
46
46
|
s.add_development_dependency(%q<i18n>, [">= 0"])
|
47
47
|
s.add_development_dependency(%q<timecop>, [">= 0"])
|
48
|
-
s.add_development_dependency(%q<actionpack>, ["~> 3.2.
|
49
|
-
s.add_development_dependency(%q<activesupport>, ["~> 3.2.
|
50
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.
|
51
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
52
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.
|
53
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<actionpack>, ["~> 3.2.9"])
|
49
|
+
s.add_development_dependency(%q<activesupport>, ["~> 3.2.9"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
54
53
|
else
|
55
54
|
s.add_dependency(%q<http_accept_language>, [">= 0"])
|
56
55
|
s.add_dependency(%q<i18n>, [">= 0"])
|
57
56
|
s.add_dependency(%q<timecop>, [">= 0"])
|
58
|
-
s.add_dependency(%q<actionpack>, ["~> 3.2.
|
59
|
-
s.add_dependency(%q<activesupport>, ["~> 3.2.
|
60
|
-
s.add_dependency(%q<rspec>, ["~> 2.
|
61
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
62
|
-
s.add_dependency(%q<jeweler>, ["~> 1.
|
63
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
57
|
+
s.add_dependency(%q<actionpack>, ["~> 3.2.9"])
|
58
|
+
s.add_dependency(%q<activesupport>, ["~> 3.2.9"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
62
|
end
|
65
63
|
else
|
66
64
|
s.add_dependency(%q<http_accept_language>, [">= 0"])
|
67
65
|
s.add_dependency(%q<i18n>, [">= 0"])
|
68
66
|
s.add_dependency(%q<timecop>, [">= 0"])
|
69
|
-
s.add_dependency(%q<actionpack>, ["~> 3.2.
|
70
|
-
s.add_dependency(%q<activesupport>, ["~> 3.2.
|
71
|
-
s.add_dependency(%q<rspec>, ["~> 2.
|
72
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
73
|
-
s.add_dependency(%q<jeweler>, ["~> 1.
|
74
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<actionpack>, ["~> 3.2.9"])
|
68
|
+
s.add_dependency(%q<activesupport>, ["~> 3.2.9"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
75
72
|
end
|
76
73
|
end
|
77
74
|
|
@@ -177,10 +177,75 @@ describe Rails::LocaleDetection do
|
|
177
177
|
|
178
178
|
end
|
179
179
|
|
180
|
-
describe '#
|
181
|
-
context
|
180
|
+
describe '#set_default_url_option_for_request?' do
|
181
|
+
context 'with a locale param' do
|
182
|
+
before :all do
|
183
|
+
controller.params[:locale] = "fr"
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'return true when set_default_url_option is true' do
|
187
|
+
Rails::LocaleDetection.set_default_url_option = true
|
188
|
+
controller.should be_set_default_url_option_for_request
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'return false when set_default_url_option is fale' do
|
192
|
+
Rails::LocaleDetection.set_default_url_option = false
|
193
|
+
controller.should_not be_set_default_url_option_for_request
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'return false when set_default_url_option is :never' do
|
197
|
+
Rails::LocaleDetection.set_default_url_option = :never
|
198
|
+
controller.should_not be_set_default_url_option_for_request
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'return true when set_default_url_option is :always' do
|
202
|
+
Rails::LocaleDetection.set_default_url_option = :always
|
203
|
+
controller.should be_set_default_url_option_for_request
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'return true when set_default_url_option is :explicitly' do
|
207
|
+
Rails::LocaleDetection.set_default_url_option = :explicitly
|
208
|
+
controller.should be_set_default_url_option_for_request
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'without a locale param' do
|
182
213
|
before :all do
|
214
|
+
controller.params[:locale] = nil
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'return true when set_default_url_option is true' do
|
183
218
|
Rails::LocaleDetection.set_default_url_option = true
|
219
|
+
controller.should be_set_default_url_option_for_request
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'return false when set_default_url_option is false' do
|
223
|
+
Rails::LocaleDetection.set_default_url_option = false
|
224
|
+
controller.should_not be_set_default_url_option_for_request
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'return false when set_default_url_option is :never' do
|
228
|
+
Rails::LocaleDetection.set_default_url_option = :never
|
229
|
+
controller.should_not be_set_default_url_option_for_request
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'return true when set_default_url_option is :always' do
|
233
|
+
Rails::LocaleDetection.set_default_url_option = :always
|
234
|
+
controller.should be_set_default_url_option_for_request
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'return false when set_default_url_option is :explicitly' do
|
238
|
+
Rails::LocaleDetection.set_default_url_option = :explicitly
|
239
|
+
controller.should_not be_set_default_url_option_for_request
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#set_locale' do
|
246
|
+
context "with set default_url_option :always" do
|
247
|
+
before :all do
|
248
|
+
Rails::LocaleDetection.set_default_url_option = :always
|
184
249
|
controller.params[:locale] = "fr"
|
185
250
|
controller.set_locale
|
186
251
|
end
|
@@ -198,9 +263,9 @@ describe Rails::LocaleDetection do
|
|
198
263
|
end
|
199
264
|
end
|
200
265
|
|
201
|
-
context "with set default_url_option
|
266
|
+
context "with set default_url_option :never" do
|
202
267
|
before :all do
|
203
|
-
Rails::LocaleDetection.set_default_url_option =
|
268
|
+
Rails::LocaleDetection.set_default_url_option = :never
|
204
269
|
controller.default_url_options = {}
|
205
270
|
controller.params[:locale] = "fr"
|
206
271
|
controller.set_locale
|
@@ -210,14 +275,57 @@ describe Rails::LocaleDetection do
|
|
210
275
|
I18n.locale.should eq(:fr)
|
211
276
|
end
|
212
277
|
|
213
|
-
it "sets the
|
278
|
+
it "sets the cookier locale" do
|
214
279
|
controller.cookies[:locale].should eq(:fr)
|
215
280
|
end
|
216
281
|
|
282
|
+
it "doesn't set the default_url_options" do
|
283
|
+
controller.default_url_options[:locale].should be_nil
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context "with set default_url_option :explicit and no locale param" do
|
288
|
+
before :all do
|
289
|
+
Rails::LocaleDetection.set_default_url_option = :explicitly
|
290
|
+
controller.default_url_options = {}
|
291
|
+
controller.params[:locale] = nil
|
292
|
+
controller.set_locale
|
293
|
+
end
|
294
|
+
|
295
|
+
it "sets the current locale to the default param" do
|
296
|
+
I18n.locale.should eq(:en)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "sets the cookie locale" do
|
300
|
+
controller.cookies[:locale].should eq(:en)
|
301
|
+
end
|
302
|
+
|
217
303
|
it "doesn't set the default_url_options" do
|
218
304
|
controller.default_url_options[:locale].should be_nil
|
219
305
|
end
|
220
306
|
end
|
307
|
+
|
308
|
+
context "with set default_url_option :explicit and a locale param" do
|
309
|
+
before :all do
|
310
|
+
Rails::LocaleDetection.set_default_url_option = :explicitly
|
311
|
+
controller.default_url_options = {}
|
312
|
+
controller.params[:locale] = :fr
|
313
|
+
controller.set_locale
|
314
|
+
end
|
315
|
+
|
316
|
+
it "sets the current locale to the default param" do
|
317
|
+
I18n.locale.should eq(:fr)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "sets the cookie locale" do
|
321
|
+
controller.cookies[:locale].should eq(:fr)
|
322
|
+
end
|
323
|
+
|
324
|
+
it "doesn't set the default_url_options" do
|
325
|
+
controller.default_url_options[:locale].should eq(:fr)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
221
329
|
end
|
222
330
|
|
223
331
|
end
|
metadata
CHANGED
@@ -1,174 +1,159 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_locale_detection
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 1.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mateo Murphy
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :runtime
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
version_requirements: *id001
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
32
15
|
name: http_accept_language
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
33
23
|
prerelease: false
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
hash: 3
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
version: "0"
|
45
|
-
version_requirements: *id002
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
46
31
|
name: i18n
|
47
|
-
|
48
|
-
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
49
38
|
type: :development
|
50
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
hash: 3
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
version_requirements: *id003
|
60
|
-
name: timecop
|
61
39
|
prerelease: false
|
62
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: timecop
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
63
54
|
type: :development
|
64
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
57
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
- 3
|
72
|
-
- 2
|
73
|
-
- 2
|
74
|
-
version: 3.2.2
|
75
|
-
version_requirements: *id004
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
76
63
|
name: actionpack
|
77
|
-
|
78
|
-
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.2.9
|
79
70
|
type: :development
|
80
|
-
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
73
|
none: false
|
82
|
-
requirements:
|
74
|
+
requirements:
|
83
75
|
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
- 3
|
88
|
-
- 2
|
89
|
-
- 2
|
90
|
-
version: 3.2.2
|
91
|
-
version_requirements: *id005
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.2.9
|
78
|
+
- !ruby/object:Gem::Dependency
|
92
79
|
name: activesupport
|
93
|
-
|
94
|
-
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 3.2.9
|
95
86
|
type: :development
|
96
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
89
|
none: false
|
98
|
-
requirements:
|
90
|
+
requirements:
|
99
91
|
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
|
103
|
-
- 2
|
104
|
-
- 3
|
105
|
-
- 0
|
106
|
-
version: 2.3.0
|
107
|
-
version_requirements: *id006
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 3.2.9
|
94
|
+
- !ruby/object:Gem::Dependency
|
108
95
|
name: rspec
|
109
|
-
|
110
|
-
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.12.0
|
111
102
|
type: :development
|
112
|
-
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
105
|
none: false
|
114
|
-
requirements:
|
106
|
+
requirements:
|
115
107
|
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
|
119
|
-
- 1
|
120
|
-
- 0
|
121
|
-
- 0
|
122
|
-
version: 1.0.0
|
123
|
-
version_requirements: *id007
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.12.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
124
111
|
name: bundler
|
125
|
-
|
126
|
-
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.3
|
127
118
|
type: :development
|
128
|
-
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
121
|
none: false
|
130
|
-
requirements:
|
122
|
+
requirements:
|
131
123
|
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
|
134
|
-
|
135
|
-
- 1
|
136
|
-
- 6
|
137
|
-
- 4
|
138
|
-
version: 1.6.4
|
139
|
-
version_requirements: *id008
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.2.3
|
126
|
+
- !ruby/object:Gem::Dependency
|
140
127
|
name: jeweler
|
141
|
-
|
142
|
-
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.8.4
|
143
134
|
type: :development
|
144
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
|
-
requirements:
|
147
|
-
- - ">="
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
hash: 3
|
150
|
-
segments:
|
151
|
-
- 0
|
152
|
-
version: "0"
|
153
|
-
version_requirements: *id009
|
154
|
-
name: rcov
|
155
135
|
prerelease: false
|
156
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 1.8.4
|
142
|
+
description: Sets the current locale of a request using a combination of params, cookies,
|
143
|
+
and http headers
|
157
144
|
email: mateo.murphy@gmail.com
|
158
145
|
executables: []
|
159
|
-
|
160
146
|
extensions: []
|
161
|
-
|
162
|
-
extra_rdoc_files:
|
147
|
+
extra_rdoc_files:
|
163
148
|
- LICENSE.txt
|
164
|
-
- README.
|
165
|
-
files:
|
149
|
+
- README.md
|
150
|
+
files:
|
166
151
|
- .document
|
167
152
|
- .rspec
|
168
153
|
- Gemfile
|
169
154
|
- Gemfile.lock
|
170
155
|
- LICENSE.txt
|
171
|
-
- README.
|
156
|
+
- README.md
|
172
157
|
- Rakefile
|
173
158
|
- VERSION
|
174
159
|
- lib/rails/locale_detection.rb
|
@@ -178,37 +163,31 @@ files:
|
|
178
163
|
- spec/spec_helper.rb
|
179
164
|
- spec/support/mock.rb
|
180
165
|
homepage: http://github.com/mateomurphy/rails_locale_detection
|
181
|
-
licenses:
|
166
|
+
licenses:
|
182
167
|
- MIT
|
183
168
|
post_install_message:
|
184
169
|
rdoc_options: []
|
185
|
-
|
186
|
-
require_paths:
|
170
|
+
require_paths:
|
187
171
|
- lib
|
188
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
173
|
none: false
|
190
|
-
requirements:
|
191
|
-
- -
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
|
194
|
-
segments:
|
174
|
+
requirements:
|
175
|
+
- - ! '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
segments:
|
195
179
|
- 0
|
196
|
-
|
197
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
hash: -3366422370482279398
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
182
|
none: false
|
199
|
-
requirements:
|
200
|
-
- -
|
201
|
-
- !ruby/object:Gem::Version
|
202
|
-
|
203
|
-
segments:
|
204
|
-
- 0
|
205
|
-
version: "0"
|
183
|
+
requirements:
|
184
|
+
- - ! '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
206
187
|
requirements: []
|
207
|
-
|
208
188
|
rubyforge_project:
|
209
|
-
rubygems_version: 1.8.
|
189
|
+
rubygems_version: 1.8.23
|
210
190
|
signing_key:
|
211
191
|
specification_version: 3
|
212
192
|
summary: locale setting for rails project
|
213
193
|
test_files: []
|
214
|
-
|
data/README.rdoc
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
= rails_locale_detection
|
2
|
-
|
3
|
-
Sets the current locale of a request using a combination of params, cookies, http headers, and an optional user object.
|
4
|
-
|
5
|
-
In turn, it checks the value of params[:locale], cookies[:locale] and HTTP_ACCEPT_LANGUAGE headers to find a locale that
|
6
|
-
corresponds to the available locales, then stores the set locale in a cookie for future requests. If a user_locale method
|
7
|
-
is provided, the return value will be used, with preference over the other locale detection methods.
|
8
|
-
|
9
|
-
== Usage
|
10
|
-
|
11
|
-
Include the gem in your Gemfile
|
12
|
-
|
13
|
-
gem 'rails_locale_detection'
|
14
|
-
|
15
|
-
Set your default and available locales
|
16
|
-
|
17
|
-
I18n.default_locale = :en
|
18
|
-
I18n.available_locales = [:en, :fr]
|
19
|
-
|
20
|
-
Call set_locale as a filter in your controllers
|
21
|
-
|
22
|
-
class ApplicationController < ActionController::Base
|
23
|
-
before_filter :set_locale
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
To support user locales, add a user_locale method
|
28
|
-
|
29
|
-
class ApplicationController < ActionController::Base
|
30
|
-
before_filter :set_locale
|
31
|
-
|
32
|
-
def user_locale
|
33
|
-
current_user.locale if current_user
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
== Configuration
|
40
|
-
|
41
|
-
The configuration options:
|
42
|
-
|
43
|
-
Rails::LocaleDetection.config do |config|
|
44
|
-
config.locale_expiry = 3.months # This sets how long the locale cookie lasts.
|
45
|
-
config.set_default_url_option = true # sets the default_url_options[:locale] to the current locale when set_locale is called
|
46
|
-
config.detection_order = [:user, :param, :cookie, :request] # set the order in which locale detection occurs. Omit values to skip those sources
|
47
|
-
end
|
48
|
-
|
49
|
-
== Contributing to rails_locale_detection
|
50
|
-
|
51
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
52
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
53
|
-
* Fork the project
|
54
|
-
* Start a feature/bugfix branch
|
55
|
-
* Commit and push until you are happy with your contribution
|
56
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
57
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
58
|
-
|
59
|
-
== Copyright
|
60
|
-
|
61
|
-
Copyright (c) 2012 Mateo Murphy. See LICENSE.txt for
|
62
|
-
further details.
|
63
|
-
|