rack-locale_memorable 0.3.2 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +14 -15
- data/lib/rack/locale_memorable/request.rb +8 -14
- data/lib/rack/locale_memorable/version.rb +1 -1
- data/lib/rack/locale_memorable.rb +3 -3
- data/rack-locale_memorable.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee932ccf31e17732f87bcbf4db7647cae4836b1424d85097da281ffe1ffaeddf
|
4
|
+
data.tar.gz: 9c807857bf6296170af7746df724aa24d90ff9f7fb22d4c41b508f365da51cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ba6eff0fbb1cd813a1ad908cea006779858702d63911592679893060b10ba0c464cef63d7a493ef366aaedac558fa85f492cbd9f6653b06de8e5baebac7ae97
|
7
|
+
data.tar.gz: ac2e798b0ac97a176af482b78f260eae3ece611c197f2435196895c869127d7cf2beb0c25d0798e5858003d369be131e7d2a097cbe8d11790a133755cb2082c6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.4] - 2022-09-28
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
- fix changelog url https://github.com/nov/rack-locale_memorable/commit/fc744c6fe1489cee12225b8cc5991a9f4d797278
|
8
|
+
|
9
|
+
## [0.3.3] - 2022-09-28
|
10
|
+
|
11
|
+
### Refactored
|
12
|
+
|
13
|
+
- requre active_support/core_ext only https://github.com/nov/rack-locale_memorable/commit/bf56b49f064a30d9688d65d2dd2901763bf31cee
|
14
|
+
- stop using request class's instance variables following response class's design https://github.com/nov/rack-locale_memorable/commit/056807010fcb5c01d4d1745f06f8a9f87aad2ec6
|
15
|
+
|
3
16
|
## [0.3.2] - 2022-09-28
|
4
17
|
|
5
18
|
### Fixed
|
data/README.md
CHANGED
@@ -21,29 +21,20 @@ Rails.application.configure do |config|
|
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
Rails.application.configure do |config|
|
28
|
-
config.middleware.insert_before Warden::Manager, Rack::LocaleMemorable
|
29
|
-
end
|
30
|
-
```
|
31
|
-
|
32
|
-
By default, this gem handles
|
24
|
+
By default, this gem handles locale variables in 3 places in the order below, and when explicit locale is specified (= when locale is specified via query params) in the request, remember it in cookie too.
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
1. `params['locale']` as explicit locale
|
27
|
+
2. `cookies['locale']` as remembered locale
|
28
|
+
3. `headers['HTTP_ACCEPT_LANGUAGE']` as implicit locale
|
37
29
|
|
38
|
-
|
30
|
+
There are several customizable options listed below.
|
39
31
|
|
40
|
-
You can customize those values
|
41
32
|
* params_key (`'locale'` by default)
|
42
33
|
* cookie_key (`'locale'` by default)
|
43
34
|
* secure_cookie (`true` by default)
|
44
35
|
* cookie_lifetime (`1.year` by default)
|
45
36
|
|
46
|
-
like below
|
37
|
+
You can customize them like below
|
47
38
|
|
48
39
|
```ruby
|
49
40
|
Rails.application.configure do |config|
|
@@ -57,6 +48,14 @@ Rails.application.configure do |config|
|
|
57
48
|
end
|
58
49
|
```
|
59
50
|
|
51
|
+
NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Rails.application.configure do |config|
|
55
|
+
config.middleware.insert_before Warden::Manager, Rack::LocaleMemorable
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
60
59
|
## Development
|
61
60
|
|
62
61
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -3,30 +3,24 @@
|
|
3
3
|
module Rack
|
4
4
|
class LocaleMemorable
|
5
5
|
class Request < Rack::Request
|
6
|
-
attr_reader :explicit_locale
|
6
|
+
attr_reader :explicit_locale
|
7
7
|
|
8
|
-
def
|
9
|
-
super env
|
10
|
-
@params_key = params_key
|
11
|
-
@cookie_key = cookie_key
|
12
|
-
end
|
13
|
-
|
14
|
-
def detect_locale
|
8
|
+
def detect_locale(params_key:, cookie_key:)
|
15
9
|
(
|
16
|
-
from_params ||
|
17
|
-
from_cookies ||
|
10
|
+
from_params(params_key) ||
|
11
|
+
from_cookies(cookie_key) ||
|
18
12
|
from_headers
|
19
13
|
)
|
20
14
|
end
|
21
15
|
|
22
16
|
private
|
23
17
|
|
24
|
-
def from_params
|
25
|
-
@explicit_locale = primary_locale_from params[
|
18
|
+
def from_params(key)
|
19
|
+
@explicit_locale = primary_locale_from params[key]
|
26
20
|
end
|
27
21
|
|
28
|
-
def from_cookies
|
29
|
-
primary_locale_from cookies[
|
22
|
+
def from_cookies(key)
|
23
|
+
primary_locale_from cookies[key]
|
30
24
|
end
|
31
25
|
|
32
26
|
def from_headers
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support'
|
4
|
-
require 'active_support/
|
4
|
+
require 'active_support/core_ext'
|
5
5
|
require 'http/accept'
|
6
6
|
require 'rack'
|
7
7
|
|
@@ -16,8 +16,8 @@ module Rack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def call(env)
|
19
|
-
request = Request.new
|
20
|
-
I18n.with_locale(request.detect_locale) do
|
19
|
+
request = Request.new env
|
20
|
+
I18n.with_locale(request.detect_locale params_key: @params_key, cookie_key: @cookie_key) do
|
21
21
|
status, headers, body = @app.call(env)
|
22
22
|
response = Response.new body, status, headers
|
23
23
|
if request.explicit_locale.present?
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = 'https://github.com/nov/rack-locale_memorable'
|
19
|
-
spec.metadata['changelog_uri'] = 'https://github.com/nov/rack-locale_memorable/CHANGELOG.md'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/nov/rack-locale_memorable/blob/main/CHANGELOG.md'
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-locale_memorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -147,7 +147,7 @@ licenses:
|
|
147
147
|
metadata:
|
148
148
|
homepage_uri: https://github.com/nov/rack-locale_memorable
|
149
149
|
source_code_uri: https://github.com/nov/rack-locale_memorable
|
150
|
-
changelog_uri: https://github.com/nov/rack-locale_memorable/CHANGELOG.md
|
150
|
+
changelog_uri: https://github.com/nov/rack-locale_memorable/blob/main/CHANGELOG.md
|
151
151
|
post_install_message:
|
152
152
|
rdoc_options: []
|
153
153
|
require_paths:
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
166
|
+
rubygems_version: 3.3.7
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Remember locale in rack layer
|