rack-user-locale 1.0.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +17 -18
- data/VERSION +1 -1
- data/lib/user_locale.rb +21 -17
- metadata +125 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0309b9693bca3c0277caa6678a05322cbcb197374e036efd9f0a1909be450a6
|
4
|
+
data.tar.gz: 0e08b6bc4d7ab39d99c56b1ad7c69036817be89c3dae5628ae35c128f349a5cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 979f73d6c22e4575c66078d0bcadec97e5498401fe778a0a3f044a083369a9b542b6891cee1daaf5cc5c34cb0435b85acb8b4c0066863cb0c96cbe96421f74cc
|
7
|
+
data.tar.gz: 2c0c1d348b5f908e48d0891ff4dae994b8160bc9e41258423f1c231a6976407616214f8559e28016f66e2cf4a7db1b5c674abd3afdea08b786862e58e9718ade
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
# Rack User Locale
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/rack-user-locale.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rack-user-locale.svg)](http://badge.fury.io/rb/rack-user-locale)
|
4
4
|
|
5
5
|
A Rack module for getting and setting a user's locale via a cookie or browser default language.
|
6
6
|
|
7
|
-
Credit to these gems for pointing me in the direction I wanted to go in...
|
8
|
-
|
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
|
12
|
-
|
13
7
|
## Installation
|
14
8
|
|
15
9
|
```
|
@@ -74,18 +68,23 @@ If you don't want to use the default cookie name of `user-locale`, you can set i
|
|
74
68
|
use Rack::UserLocale, cookie_name: "some-cookie-name"
|
75
69
|
```
|
76
70
|
|
77
|
-
##
|
71
|
+
## Inspiration
|
72
|
+
|
73
|
+
Credit to these gems for pointing me in the direction I wanted to go in...
|
74
|
+
|
75
|
+
- https://github.com/rack/rack-contrib/blob/main/lib/rack/contrib/locale.rb
|
76
|
+
- https://github.com/jeremyvdw/rack-locale-selector
|
77
|
+
- https://github.com/jeffersongirao/rack-locale_chooser
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
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.
|
82
|
+
|
83
|
+
## License
|
78
84
|
|
79
|
-
|
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.
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
86
86
|
|
87
|
-
##
|
87
|
+
## Code of Conduct
|
88
88
|
|
89
|
-
|
89
|
+
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
90
|
|
91
|
-
See LICENSE.txt for further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.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
|
-
|
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
|
-
|
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
|
59
|
-
|
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
|
63
|
-
@
|
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
|
75
|
-
new_locale = check_accepted? ? accepted_locale(
|
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.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -16,28 +16,98 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
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.
|
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
|
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
|
40
|
+
version: 2.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-fail-fast
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-macos-notification
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.4'
|
41
111
|
- !ruby/object:Gem::Dependency
|
42
112
|
name: rack-test
|
43
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,10 +136,52 @@ dependencies:
|
|
66
136
|
- - "~>"
|
67
137
|
- !ruby/object:Gem::Version
|
68
138
|
version: '13.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.7'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
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'
|
69
181
|
description: A Rack module for getting and setting a user's locale via a cookie or
|
70
182
|
browser default language.
|
71
183
|
email:
|
72
|
-
-
|
184
|
+
- code@technicalpanda.co.uk
|
73
185
|
executables: []
|
74
186
|
extensions: []
|
75
187
|
extra_rdoc_files: []
|
@@ -80,11 +192,11 @@ files:
|
|
80
192
|
- VERSION
|
81
193
|
- lib/rack/user-locale/version.rb
|
82
194
|
- lib/user_locale.rb
|
83
|
-
homepage: https://github.com/
|
195
|
+
homepage: https://github.com/technicalpanda/rack-user-locale
|
84
196
|
licenses:
|
85
197
|
- MIT
|
86
198
|
metadata: {}
|
87
|
-
post_install_message:
|
199
|
+
post_install_message:
|
88
200
|
rdoc_options: []
|
89
201
|
require_paths:
|
90
202
|
- lib
|
@@ -92,15 +204,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
204
|
requirements:
|
93
205
|
- - ">="
|
94
206
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
207
|
+
version: '2.5'
|
96
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
209
|
requirements:
|
98
210
|
- - ">="
|
99
211
|
- !ruby/object:Gem::Version
|
100
212
|
version: '0'
|
101
213
|
requirements: []
|
102
|
-
rubygems_version: 3.1.
|
103
|
-
signing_key:
|
214
|
+
rubygems_version: 3.1.4
|
215
|
+
signing_key:
|
104
216
|
specification_version: 4
|
105
217
|
summary: A Rack module for getting and setting a user's locale
|
106
218
|
test_files: []
|