rack-user-locale 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +20 -16
  4. data/VERSION +1 -1
  5. data/lib/user_locale.rb +21 -17
  6. metadata +49 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39d2236bcd061b79e92a196c564fc2b3e09053ed063a272128cc81d29610d4f2
4
- data.tar.gz: cca5a0b5b88dd00cd575ee3ae811f41ce7d233a7ddf11be6d99fd450c80efdd7
3
+ metadata.gz: 8982fb78cc25313df0ca651d149980652b6142bba52bc75881a3a45c33b2b8ca
4
+ data.tar.gz: 48f868e8593a5b805ed8d76af0dfb14d4535080908ec1a58ca1e0c7164135748
5
5
  SHA512:
6
- metadata.gz: '0533867d9f8ce4113b9c3b6cafea2bc016508b05755019d89b04a94baec798a12e74802ef5ec55a9546986ffb43f0cf4d4df509c778380b02ba386692b4095ae'
7
- data.tar.gz: 8558978f95d16347b585367c987e99e5c52f0bc6cc41f83d9f25b59f063f7daea18310254ce334a2dc04e98cdf779dd8643a87a379820b042d3ed44493febee6
6
+ metadata.gz: 37430d6692f2d3f7ea56a855884b28ec134daa3e230b9a7c3c45ed5758ba433844e10a4bbbde55bbe4c81abc6cc55a8a218558db96f888f49a116a725fbbf7c9
7
+ data.tar.gz: 21001598fc4c7dec529f0d28ca90d55d88f74be1a8b0d7074187b9d7e03f160aede26b85b87444f766104a9345cbca9380c629ff4bd000f364afeb641bc1ebc7
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2020 Stuart Chinery
1
+ Copyright (c) 2021 Technical Panda Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,14 +1,13 @@
1
1
  # Rack User Locale
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/rack-user-locale.png)](http://badge.fury.io/rb/rack-user-locale) [![Build Status](https://secure.travis-ci.org/schinery/rack-user-locale.png)](http://travis-ci.org/schinery/rack-user-locale)
3
+ [![Gem Version](https://badge.fury.io/rb/rack-user-locale.svg)](http://badge.fury.io/rb/rack-user-locale)
4
+ ![CI](https://github.com/technicalpanda/rack-user-locale/workflows/CI/badge.svg)
4
5
 
5
6
  A Rack module for getting and setting a user's locale via a cookie or browser default language.
6
7
 
7
- Credit to these gems for pointing me in the direction I wanted to go in...
8
+ ## Requirements
8
9
 
9
- - https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb
10
- - https://github.com/jeremyvdw/rack-locale-selector
11
- - https://github.com/jeffersongirao/rack-locale_chooser
10
+ * Ruby >= 2.7
12
11
 
13
12
  ## Installation
14
13
 
@@ -74,18 +73,23 @@ If you don't want to use the default cookie name of `user-locale`, you can set i
74
73
  use Rack::UserLocale, cookie_name: "some-cookie-name"
75
74
  ```
76
75
 
77
- ## Contributing to rack-user-locale
76
+ ## Inspiration
77
+
78
+ Credit to these gems for pointing me in the direction I wanted to go in...
79
+
80
+ - https://github.com/rack/rack-contrib/blob/main/lib/rack/contrib/locale.rb
81
+ - https://github.com/jeremyvdw/rack-locale-selector
82
+ - https://github.com/jeffersongirao/rack-locale_chooser
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/technicalpanda/rack-user-locale. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
87
+
88
+ ## License
78
89
 
79
- - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
80
- - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
81
- - Fork the project.
82
- - Start a feature/bugfix branch.
83
- - Commit and push until you are happy with your contribution.
84
- - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
85
- - 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.
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
91
 
87
- ## Copyright
92
+ ## Code of Conduct
88
93
 
89
- Copyright (c) 2020 [Stuart Chinery](https://github.com/schinery) and [Dave Hrycyszyn](https://github.com/futurechimp).
94
+ Everyone interacting with this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/technicalpanda/rack-user-locale/blob/main/CODE_OF_CONDUCT.md).
90
95
 
91
- See LICENSE.txt for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 2.0.0
data/lib/user_locale.rb CHANGED
@@ -16,7 +16,7 @@ module Rack
16
16
 
17
17
  def call(env)
18
18
  @env = env
19
- set_i18n_locale
19
+ set_i18n
20
20
  app.call(env) && return unless request.get?
21
21
 
22
22
  @status, @headers, @body = app.call(env)
@@ -31,16 +31,7 @@ module Rack
31
31
  end
32
32
 
33
33
  def browser_locale
34
- return if http_accept_languages.nil?
35
-
36
- if check_accepted?
37
- weighted_langs.each do |lang|
38
- l = accepted_locale(split_lang(lang.first).to_sym)
39
- return l unless l.nil?
40
- end
41
- end
42
-
43
- split_lang(weighted_langs.first.first)
34
+ @browser_locale ||= detect_browser_locale
44
35
  end
45
36
 
46
37
  def check_accepted?
@@ -55,12 +46,21 @@ module Rack
55
46
  @default_locale ||= I18n.default_locale
56
47
  end
57
48
 
58
- def http_accept_languages
59
- @http_accept_languages ||= env["HTTP_ACCEPT_LANGUAGE"]
49
+ def detect_browser_locale
50
+ return if http_accept_languages.nil?
51
+
52
+ if check_accepted?
53
+ weighted_langs.each do |lang|
54
+ l = accepted_locale(split_lang(lang.first).to_sym)
55
+ return l unless l.nil?
56
+ end
57
+ end
58
+
59
+ split_lang(weighted_langs.first.first)
60
60
  end
61
61
 
62
- def locale
63
- @locale ||= cookie_locale || browser_locale || default_locale
62
+ def http_accept_languages
63
+ @http_accept_languages ||= env["HTTP_ACCEPT_LANGUAGE"]
64
64
  end
65
65
 
66
66
  def request
@@ -71,8 +71,8 @@ module Rack
71
71
  @response ||= Rack::Response.new(body, status, headers)
72
72
  end
73
73
 
74
- def set_i18n_locale
75
- new_locale = check_accepted? ? accepted_locale(locale.to_sym, default_locale) : locale.to_sym
74
+ def set_i18n
75
+ new_locale = check_accepted? ? accepted_locale(user_locale.to_sym, default_locale) : user_locale.to_sym
76
76
  I18n.locale = env["rack.locale"] = new_locale
77
77
  end
78
78
 
@@ -95,6 +95,10 @@ module Rack
95
95
  lang.split("-").first
96
96
  end
97
97
 
98
+ def user_locale
99
+ @user_locale ||= cookie_locale || browser_locale || default_locale
100
+ end
101
+
98
102
  def weighted_langs
99
103
  @weighted_langs ||= split_http_accept_languages.sort { |a, b| b[1] <=> a[1] }
100
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-user-locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Chinery
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.0
19
+ version: 1.8.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.0
26
+ version: 1.8.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.8
33
+ version: 2.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.8
40
+ version: 2.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '11.0'
47
+ version: '11.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '11.0'
54
+ version: '11.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.13'
61
+ version: '5.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.13'
68
+ version: '5.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-fail-fast
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -142,18 +142,46 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.78'
145
+ version: '1.7'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0.78'
152
+ version: '1.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-minitest
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.10'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.10'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rake
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.5'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.5'
153
181
  description: A Rack module for getting and setting a user's locale via a cookie or
154
182
  browser default language.
155
183
  email:
156
- - stuart.chinery@gmail.com
184
+ - code@technicalpanda.co.uk
157
185
  executables: []
158
186
  extensions: []
159
187
  extra_rdoc_files: []
@@ -164,11 +192,12 @@ files:
164
192
  - VERSION
165
193
  - lib/rack/user-locale/version.rb
166
194
  - lib/user_locale.rb
167
- homepage: https://github.com/schinery/rack-user-locale
195
+ homepage: https://github.com/technicalpanda/rack-user-locale
168
196
  licenses:
169
197
  - MIT
170
- metadata: {}
171
- post_install_message:
198
+ metadata:
199
+ rubygems_mfa_required: 'true'
200
+ post_install_message:
172
201
  rdoc_options: []
173
202
  require_paths:
174
203
  - lib
@@ -176,15 +205,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
205
  requirements:
177
206
  - - ">="
178
207
  - !ruby/object:Gem::Version
179
- version: '0'
208
+ version: '2.7'
180
209
  required_rubygems_version: !ruby/object:Gem::Requirement
181
210
  requirements:
182
211
  - - ">="
183
212
  - !ruby/object:Gem::Version
184
213
  version: '0'
185
214
  requirements: []
186
- rubygems_version: 3.1.2
187
- signing_key:
215
+ rubygems_version: 3.2.33
216
+ signing_key:
188
217
  specification_version: 4
189
218
  summary: A Rack module for getting and setting a user's locale
190
219
  test_files: []