rack-user-locale 1.0.2 → 1.1.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 +2 -1
- data/VERSION +1 -1
- data/lib/user_locale.rb +21 -17
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dc51ae0380e03d6cb6b2d97f76c35046ce797743542438d4034b325208f858e
|
4
|
+
data.tar.gz: 771dfb2612220a99c331d38b1814a1559f9fcacdb3e1ed415547cf0e4dd268c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1aa1b2a4b177f9d7b0df84ce5c7b64e170a47e999f35732ed89fb7c787ddb1fc3483710d217e2480af3be1765d412bcf4ca9aa1cf9650339ecf27e9394ad62f
|
7
|
+
data.tar.gz: d4ec84e5e50d6a1a99591a32eec18bd5f35641b7d1a163e113f8b5520202575fa804965d1658342bbf125379f609a8cfa49efb0caa5fcd66d4f0544fdab9a418
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
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)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rack-user-locale.png)](http://badge.fury.io/rb/rack-user-locale)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/schinery/rack-user-locale.png)](http://travis-ci.org/schinery/rack-user-locale)
|
4
5
|
|
5
6
|
A Rack module for getting and setting a user's locale via a cookie or browser default language.
|
6
7
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Chinery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01
|
11
|
+
date: 2020-02-01 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.
|
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.
|
33
|
+
version: 2.1.2
|
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.
|
40
|
+
version: 2.1.2
|
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.
|
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.
|
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.
|
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.
|
68
|
+
version: '5.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest-fail-fast
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0.
|
145
|
+
version: '0.79'
|
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.
|
152
|
+
version: '0.79'
|
153
153
|
description: A Rack module for getting and setting a user's locale via a cookie or
|
154
154
|
browser default language.
|
155
155
|
email:
|