rack-locale_memorable 0.4.1 → 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: c5fa88bee1ecee1f29896cc46819466cc62ff1e673e709d727ed8a50a455ae0f
4
- data.tar.gz: e19e763fe6ab18649ad21c50fbc8a0556f7b27020266114379815106c2d29ec7
3
+ metadata.gz: 0ffe06754e47f1f4e78b11466c82b3e6eec83328a39ced2f7643531cf13663d5
4
+ data.tar.gz: feeb7868eb676e2b53e2e8cb6d6f72344c54ce0f1552a0bac81ade90afbf1d63
5
5
  SHA512:
6
- metadata.gz: 16175263afb06a7ab63088895a78d9112f10d0b9f1e384fd1481c56c0acf1a44ea5b16f1e7f1cb3e439945020d533fb8179976b768d190a1ce431bde4a55493c
7
- data.tar.gz: 9099bd43efbf47653789c4c679ff805561d9b90d4562991176dc16fa6cb5492d569acd8cf63382079a25f2d94b1b1ba8d7fa50f1e489ef3d5477aa48b8344745
6
+ metadata.gz: 110f31d182de015b71c26bf2b9d952537c4444966efabe116c2a67d8eee59196d24515cb37a34df66f0d3d1fb308e74626ec11aac1d43f38feb932b79726f3f9
7
+ data.tar.gz: 16359f3551313019d6b346e071b520fd2dae13e44d6715149f95e2bc15ad77bfe7688aca30e3349b373ef40d9808a0c5bb657056192ab9def3ccc9a02971e920
data/CHANGELOG.md CHANGED
@@ -1,12 +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
+
3
9
  ## [0.4.1] - 2022-09-29
4
10
 
5
11
  ### Fixed
6
12
 
7
13
  - make default path "/" https://github.com/nov/rack-locale_memorable/commit/439868e4d2f6a917be1234fa2d9bdbfab41fce69
8
14
 
9
-
10
15
  ## [0.4.0] - 2022-09-28
11
16
 
12
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.
@@ -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.1'
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.1
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-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