rack-locale_memorable 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5fa88bee1ecee1f29896cc46819466cc62ff1e673e709d727ed8a50a455ae0f
4
- data.tar.gz: e19e763fe6ab18649ad21c50fbc8a0556f7b27020266114379815106c2d29ec7
3
+ metadata.gz: fa0c01424f46339976170cf682e5bfa2dc9d9fa7d07dd43f8a879364b0aad2b3
4
+ data.tar.gz: 15f3723e2480bf0383cc10f34c5fe317006ecde186f89ec25846db244e69194c
5
5
  SHA512:
6
- metadata.gz: 16175263afb06a7ab63088895a78d9112f10d0b9f1e384fd1481c56c0acf1a44ea5b16f1e7f1cb3e439945020d533fb8179976b768d190a1ce431bde4a55493c
7
- data.tar.gz: 9099bd43efbf47653789c4c679ff805561d9b90d4562991176dc16fa6cb5492d569acd8cf63382079a25f2d94b1b1ba8d7fa50f1e489ef3d5477aa48b8344745
6
+ metadata.gz: b18e7390e5a87613d9b67f4373587ea38b412396698f1f25f3f5cebb6b094d637616b13177733bb9c1e2968c534763953f7490ff1eea4915ebc9eca9fd067d8e
7
+ data.tar.gz: ed28ed315f1f27d1e6f6780a7ab2117a848cff1f609247baf806189d995eacc56c397890c524abf28438dbd4a9e482b4a006dcea8205268c5b0379faa417d9ad
data/CHANGELOG.md CHANGED
@@ -1,12 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0] - 2022-10-01
4
+
5
+ ### Changed
6
+
7
+ - remove activesupport https://github.com/nov/rack-locale_memorable/pull/2
8
+
9
+ ## [0.5.0] - 2022-10-01
10
+
11
+ ### Changed
12
+
13
+ - set env['rack.locale'] and Content-Language response header following rack-locale https://github.com/nov/rack-locale_memorable/commit/02e34752327141f2dcd9f3ccfce3838c7e742abd
14
+
3
15
  ## [0.4.1] - 2022-09-29
4
16
 
5
17
  ### Fixed
6
18
 
7
19
  - make default path "/" https://github.com/nov/rack-locale_memorable/commit/439868e4d2f6a917be1234fa2d9bdbfab41fce69
8
20
 
9
-
10
21
  ## [0.4.0] - 2022-09-28
11
22
 
12
23
  ### Changed
data/README.md CHANGED
@@ -2,6 +2,10 @@
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) handles i18n strings in rack-middleware layer, setting `I18n.locale` is not enough for some cases.
6
+
7
+ This gem sets `I18n.locale` in rack-middleware layer, so that you can let other rack-middlewares use proper `I18n.locale`.
8
+
5
9
  ## Installation
6
10
 
7
11
  Install the gem and add to the application's Gemfile by executing:
@@ -33,7 +37,7 @@ There are several customizable options listed below.
33
37
  * `cookie_key` (`'locale'` by default)
34
38
  * `cookie_options[:lifetime]` (`1.year` by default)
35
39
  * `cookie_options[:domain]` (`nil` by default)
36
- * `cookie_options[:path]` (`nil` by default)
40
+ * `cookie_options[:path]` (`/` by default)
37
41
  * `cookie_options[:http_only]` (`true` by default)
38
42
  * `cookie_options[:secure]` (`true` by default)
39
43
 
@@ -64,6 +68,51 @@ Rails.application.configure do |config|
64
68
  end
65
69
  ```
66
70
 
71
+ ref.) related issue in devise & warden
72
+ * https://github.com/heartcombo/devise/issues/5247
73
+ * https://github.com/wardencommunity/warden/issues/180
74
+
75
+
76
+ ## Detailed locale handling
77
+
78
+ See rspec results.
79
+
80
+ ```console
81
+ % bundle exec rspec --format=documentation
82
+
83
+ Rack::LocaleMemorable
84
+ with no locales
85
+ behaves like handled_with_default_locale
86
+ should use default locale
87
+ channel priority
88
+ when locale is specified
89
+ via query
90
+ when different locale is included
91
+ in cookie
92
+ behaves like handled_with_expected_locale
93
+ should use expected locale
94
+ behaves like remember_expected_locale
95
+ should remember expected locale
96
+ in header
97
+ behaves like handled_with_expected_locale
98
+ should use expected locale
99
+ behaves like remember_expected_locale
100
+ should remember expected locale
101
+ in cookie & header
102
+ behaves like handled_with_expected_locale
103
+ should use expected locale
104
+ behaves like remember_expected_locale
105
+ should remember expected locale
106
+ via cookie
107
+ when different locale is included
108
+ in header
109
+ behaves like handled_with_expected_locale
110
+ should use expected locale
111
+ behaves like remember_no_locale
112
+ should not remember any locale
113
+ :
114
+ ```
115
+
67
116
  ## Development
68
117
 
69
118
  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.
@@ -28,7 +28,7 @@ module Rack
28
28
  end
29
29
 
30
30
  def primary_locale_from(locales)
31
- available_locales_from(locales)&.first if locales.present?
31
+ available_locales_from(locales)&.first if locales
32
32
  end
33
33
 
34
34
  def available_locales_from(locales)
@@ -3,16 +3,21 @@
3
3
  module Rack
4
4
  class LocaleMemorable
5
5
  class Response < Rack::Response
6
- def remember_locale(explicit_locale, key:, lifetime: 1.year, domain: nil, path: '/', http_only: true, secure: true)
6
+ def remember_locale(explicit_locale, key:, lifetime: 31536000, domain: nil, path: '/', http_only: true, secure: true)
7
7
  set_cookie key, {
8
8
  value: explicit_locale,
9
- expires: lifetime.from_now,
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
13
  secure: secure
14
14
  }.compact
15
15
  end
16
+
17
+ def finish
18
+ headers['Content-Language'] ||= I18n.locale.to_s
19
+ super
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class LocaleMemorable
5
- VERSION = '0.4.1'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support'
4
- require 'active_support/core_ext'
3
+ require 'i18n'
5
4
  require 'http/accept'
6
5
  require 'rack'
7
6
 
@@ -17,13 +16,11 @@ module Rack
17
16
  def call(env)
18
17
  request = Request.new env
19
18
  I18n.with_locale(request.detect_locale params_key: @params_key, cookie_key: @cookie_key) do
19
+ env['rack.locale'] = I18n.locale.to_s
20
20
  status, headers, body = @app.call(env)
21
21
  response = Response.new body, status, headers
22
- if request.explicit_locale.present?
23
- response.remember_locale(
24
- request.explicit_locale,
25
- **@cookie_options.merge(key: @cookie_key)
26
- )
22
+ if request.explicit_locale
23
+ response.remember_locale request.explicit_locale, key: @cookie_key, **@cookie_options
27
24
  end
28
25
  response.finish
29
26
  end
@@ -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: 0.4.1
4
+ version: 1.0.0
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-29 00:00:00.000000000 Z
11
+ date: 2022-10-01 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