rack-locale_memorable 0.5.0 → 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/CHANGELOG.md +6 -0
- data/README.md +5 -3
- data/Rakefile +12 -0
- data/lib/rack/locale_memorable/request.rb +1 -1
- data/lib/rack/locale_memorable/response.rb +4 -3
- data/lib/rack/locale_memorable/version.rb +1 -1
- data/lib/rack/locale_memorable.rb +3 -4
- data/rack-locale_memorable.gemspec +2 -3
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9efbac61d08eec634b8977fc7c223f50c6dcd6cba0cfd09d7b368c3bd9f8eee9
|
4
|
+
data.tar.gz: e5c23a00f8386c708e24b3279c91c15bf71631153ece153c1904995f326424fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3fced878df7d908990f9962c18375e39b9c569f687bb07ef53bb53870154ca248e7bcea5a660c9689df8562140d64a8a0f5f0a29eefa2bfe451cb487549ffb9
|
7
|
+
data.tar.gz: 68b01b69ed47d96825a705d65fd234ce4e703ac93ded7c8f646ba4aeb82ef3b4c68b4421b4f8a1746cac2fc6c8d5d00fd30085c7e08352d524a794b55899350a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Handle query params, cookie and HTTP_ACCEPT_LANGUAGE header to detect user-preffered locale, and remember it when necessary.
|
4
4
|
|
5
|
-
Since some libraries (e.g., Devise & Warden)
|
5
|
+
Since some libraries (e.g., Devise & Warden) or applications may handle i18n strings in rack-middleware layer, setting `I18n.locale` in Rails layer is not enough in such cases.
|
6
6
|
|
7
7
|
This gem sets `I18n.locale` in rack-middleware layer, so that you can let other rack-middlewares use proper `I18n.locale`.
|
8
8
|
|
@@ -40,6 +40,7 @@ There are several customizable options listed below.
|
|
40
40
|
* `cookie_options[:path]` (`/` by default)
|
41
41
|
* `cookie_options[:http_only]` (`true` by default)
|
42
42
|
* `cookie_options[:secure]` (`true` by default)
|
43
|
+
* `cookie_options[:same_site]` (`nil` by default)
|
43
44
|
|
44
45
|
You can customize them like below
|
45
46
|
|
@@ -54,13 +55,14 @@ Rails.application.configure do |config|
|
|
54
55
|
domain: 'example.com',
|
55
56
|
path: '/localized',
|
56
57
|
http_only: false,
|
57
|
-
secure: Rails.env.production
|
58
|
+
secure: Rails.env.production?,
|
59
|
+
same_site :none
|
58
60
|
}
|
59
61
|
)
|
60
62
|
end
|
61
63
|
```
|
62
64
|
|
63
|
-
NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you see warden error messages in wrong locale.
|
65
|
+
NOTE: If you're using devise, set `Rack::LocaleMemorable` before `Warden::Manager`, otherwise you might see warden error messages in wrong locale.
|
64
66
|
|
65
67
|
```ruby
|
66
68
|
Rails.application.configure do |config|
|
data/Rakefile
CHANGED
@@ -5,4 +5,16 @@ require 'rspec/core/rake_task'
|
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
+
namespace :coverage do
|
9
|
+
desc "Open coverage report"
|
10
|
+
task :report do
|
11
|
+
require 'simplecov'
|
12
|
+
`open "#{File.join SimpleCov.coverage_path, 'index.html'}"`
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task :spec do
|
17
|
+
Rake::Task[:'coverage:report'].invoke unless ENV['GITHUB_ACTIONS']
|
18
|
+
end
|
19
|
+
|
8
20
|
task default: :spec
|
@@ -3,14 +3,15 @@
|
|
3
3
|
module Rack
|
4
4
|
class LocaleMemorable
|
5
5
|
class Response < Rack::Response
|
6
|
-
def remember_locale(explicit_locale, key:, lifetime:
|
6
|
+
def remember_locale(explicit_locale, key:, lifetime: 31536000, domain: nil, path: '/', http_only: true, secure: true, same_site: nil)
|
7
7
|
set_cookie key, {
|
8
8
|
value: explicit_locale,
|
9
|
-
expires: lifetime.
|
9
|
+
expires: Time.at(Time.now.to_i + lifetime.to_i),
|
10
10
|
domain: domain,
|
11
11
|
path: path,
|
12
12
|
http_only: http_only,
|
13
|
-
secure: secure
|
13
|
+
secure: secure,
|
14
|
+
same_site: same_site
|
14
15
|
}.compact
|
15
16
|
end
|
16
17
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/core_ext'
|
3
|
+
require 'i18n'
|
5
4
|
require 'http/accept'
|
6
5
|
require 'rack'
|
7
6
|
|
@@ -16,11 +15,11 @@ module Rack
|
|
16
15
|
|
17
16
|
def call(env)
|
18
17
|
request = Request.new env
|
19
|
-
I18n.with_locale
|
18
|
+
I18n.with_locale request.detect_locale(params_key: @params_key, cookie_key: @cookie_key) do
|
20
19
|
env['rack.locale'] = I18n.locale.to_s
|
21
20
|
status, headers, body = @app.call(env)
|
22
21
|
response = Response.new body, status, headers
|
23
|
-
if request.explicit_locale
|
22
|
+
if request.explicit_locale
|
24
23
|
response.remember_locale request.explicit_locale, key: @cookie_key, **@cookie_options
|
25
24
|
end
|
26
25
|
response.finish
|
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.required_ruby_version = '>= 2.7.0'
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
-
spec.metadata['source_code_uri'] =
|
19
|
-
spec.metadata['changelog_uri'] = '
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
spec.metadata['changelog_uri'] = File.join(spec.homepage, '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.
|
@@ -32,7 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_dependency 'rack'
|
33
33
|
spec.add_dependency 'i18n'
|
34
34
|
spec.add_dependency 'http-accept'
|
35
|
-
spec.add_dependency 'activesupport'
|
36
35
|
spec.add_development_dependency 'rake'
|
37
36
|
spec.add_development_dependency 'rspec'
|
38
37
|
spec.add_development_dependency 'simplecov'
|
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activesupport
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
163
|
- !ruby/object:Gem::Version
|
178
164
|
version: '0'
|
179
165
|
requirements: []
|
180
|
-
rubygems_version: 3.3.
|
166
|
+
rubygems_version: 3.3.26
|
181
167
|
signing_key:
|
182
168
|
specification_version: 4
|
183
169
|
summary: Remember locale in rack layer
|