rack-locale_memorable 0.4.0 → 0.5.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: 55bce36ab6b80c79c3057df44cbb98797093e1a10fba2d7f4614391a1472d0f2
4
- data.tar.gz: feec52c485b6fe3056cc15c2137193d04a1430b058d84b53e42e91d25b173e0a
3
+ metadata.gz: 0ffe06754e47f1f4e78b11466c82b3e6eec83328a39ced2f7643531cf13663d5
4
+ data.tar.gz: feeb7868eb676e2b53e2e8cb6d6f72344c54ce0f1552a0bac81ade90afbf1d63
5
5
  SHA512:
6
- metadata.gz: 5810a02bef7643ccd1c59fb4668813085ad223f7127985d7fb779b13c71438099fdf7f902b43aa0d784d9607d40e05ff402182bf20ae072c12b4244633368fa1
7
- data.tar.gz: d9f6b533cace763569959f1431bf34f68988b91717e9c85b87ef56fa46bd84b3d853ec4d78222d438d507ce72220dfcda77924bf91d3cc920cf7145cb0e82394
6
+ metadata.gz: 110f31d182de015b71c26bf2b9d952537c4444966efabe116c2a67d8eee59196d24515cb37a34df66f0d3d1fb308e74626ec11aac1d43f38feb932b79726f3f9
7
+ data.tar.gz: 16359f3551313019d6b346e071b520fd2dae13e44d6715149f95e2bc15ad77bfe7688aca30e3349b373ef40d9808a0c5bb657056192ab9def3ccc9a02971e920
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2022-10-01
4
+
5
+ ### Changed
6
+
7
+ - set env['rack.locale'] and Content-Language response header following rack-locale https://github.com/nov/rack-locale_memorable/commit/02e34752327141f2dcd9f3ccfce3838c7e742abd
8
+
9
+ ## [0.4.1] - 2022-09-29
10
+
11
+ ### Fixed
12
+
13
+ - make default path "/" https://github.com/nov/rack-locale_memorable/commit/439868e4d2f6a917be1234fa2d9bdbfab41fce69
14
+
3
15
  ## [0.4.0] - 2022-09-28
4
16
 
5
17
  ### 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.
@@ -3,7 +3,7 @@
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: nil, http_only: true, secure: true)
6
+ def remember_locale(explicit_locale, key:, lifetime: 1.year, domain: nil, path: '/', http_only: true, secure: true)
7
7
  set_cookie key, {
8
8
  value: explicit_locale,
9
9
  expires: lifetime.from_now,
@@ -13,6 +13,11 @@ module Rack
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.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -17,13 +17,11 @@ module Rack
17
17
  def call(env)
18
18
  request = Request.new env
19
19
  I18n.with_locale(request.detect_locale params_key: @params_key, cookie_key: @cookie_key) do
20
+ env['rack.locale'] = I18n.locale.to_s
20
21
  status, headers, body = @app.call(env)
21
22
  response = Response.new body, status, headers
22
23
  if request.explicit_locale.present?
23
- response.remember_locale(
24
- request.explicit_locale,
25
- **@cookie_options.merge(key: @cookie_key)
26
- )
24
+ response.remember_locale request.explicit_locale, key: @cookie_key, **@cookie_options
27
25
  end
28
26
  response.finish
29
27
  end
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.0
4
+ version: 0.5.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-28 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