route_translator 9.0.0 → 10.0.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 +8 -0
- data/LICENSE +1 -1
- data/README.md +2 -3
- data/lib/route_translator.rb +2 -5
- data/lib/route_translator/extensions/route_set.rb +2 -2
- data/lib/route_translator/host.rb +8 -8
- data/lib/route_translator/translator.rb +1 -4
- data/lib/route_translator/translator/path.rb +1 -2
- data/lib/route_translator/translator/path/segment.rb +1 -2
- data/lib/route_translator/version.rb +1 -1
- metadata +41 -15
- data/lib/route_translator/host_path_consistency_lambdas.rb +0 -21
- data/lib/route_translator/locale_sanitizer.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ba0fdafb1a82378946c98b7c75a8c659fa83daba8254def31c34a73d8ac243c
|
4
|
+
data.tar.gz: dd8f448c13448b158d5511e36ebba28bbfd6a2a8eaa2f1f7b387d803d735b654
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cb4821500c0ca720fb8dac607c8d349f67e54fa2b9424b5418241e29526bcc6632fd19b8420ab4ff52195eb61cbb0adc6cb9084b43005a17d8f2bc0ab177e47
|
7
|
+
data.tar.gz: 56ddc940436e550ed783bd0b83ced6418ecb06ff1a5a5332218b1d4f1e02e051c825c7020aa22eca795477d1c7d250bd2a064de94bd61f76e5393d790e73ee58
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 10.0.0 / 2021-01-16
|
4
|
+
|
5
|
+
* [BUGFIX] Verify host path consistency by default ([#91](https://github.com/enriclluelles/route_translator/issues/91), [#171](https://github.com/enriclluelles/route_translator/issues/171))
|
6
|
+
* [FEATURE] Remove the option to verify host path consistency
|
7
|
+
* [ENHANCEMENT] Avoid duplicate routes when using host_locales ([#87](https://github.com/enriclluelles/route_translator/issues/87), [#171](https://github.com/enriclluelles/route_translator/issues/171))
|
8
|
+
* [ENHANCEMENT] Test against Ruby 3.0.0
|
9
|
+
* [ENHANCEMENT] Update development dependencies
|
10
|
+
|
3
11
|
## 9.0.0 / 2020-11-07
|
4
12
|
|
5
13
|
* [ENHANCEMENT] Check for `empty?` instead of `any?` on available_locales array
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es],
|
3
|
+
Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es], 2021 Geremia Taglialatela
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -281,7 +281,6 @@ end
|
|
281
281
|
| `host_locales` | Sets `I18n.locale` based on `request.host`. Useful for apps accepting requests from more than one domain. See below for more details | `{}` |
|
282
282
|
| `locale_param_key` | The param key used to set the locale to the newly generated routes | `:locale` |
|
283
283
|
| `locale_segment_proc` | The locale segment of the url will by default be `locale.to_s.downcase`. You can supply your own mechanism via a Proc that takes `locale` as an argument, e.g. `->(locale) { locale.to_s.upcase }` | `false` |
|
284
|
-
| `verify_host_path_consistency` | Forces a matching of the host associated locale with the translated path locale as part of the route definition. By default, if you use different hosts to translate your application, all translated paths will work on all hosts | `false` |
|
285
284
|
|
286
285
|
|
287
286
|
### Host-based Locale
|
@@ -313,13 +312,13 @@ RouteTranslator.config.host_locales = { 'russia.*' => :ru, '*.com' => :en } #
|
|
313
312
|
RouteTranslator.config.host_locales = { '*.com' => :en, 'russia.*' => :ru } # 'russia.com' will have locale :en
|
314
313
|
```
|
315
314
|
|
316
|
-
If `host_locales` option is set, the following options will be forced
|
315
|
+
If `host_locales` option is set, the following options will be forced:
|
317
316
|
|
318
317
|
```ruby
|
319
318
|
@config.force_locale = false
|
320
319
|
@config.generate_unlocalized_routes = false
|
321
320
|
@config.generate_unnamed_unlocalized_routes = false
|
322
|
-
@config.hide_locale =
|
321
|
+
@config.hide_locale = true
|
323
322
|
```
|
324
323
|
|
325
324
|
This is to avoid odd behaviour brought about by route conflicts and because `host_locales` forces and hides the host-locale dynamically.
|
data/lib/route_translator.rb
CHANGED
@@ -6,8 +6,6 @@ require 'addressable/uri'
|
|
6
6
|
require 'route_translator/extensions'
|
7
7
|
require 'route_translator/translator'
|
8
8
|
require 'route_translator/host'
|
9
|
-
require 'route_translator/host_path_consistency_lambdas'
|
10
|
-
require 'route_translator/locale_sanitizer'
|
11
9
|
|
12
10
|
module RouteTranslator
|
13
11
|
extend RouteTranslator::Host
|
@@ -23,8 +21,7 @@ module RouteTranslator
|
|
23
21
|
hide_locale: false,
|
24
22
|
host_locales: {},
|
25
23
|
locale_param_key: :locale,
|
26
|
-
locale_segment_proc: false
|
27
|
-
verify_host_path_consistency: false
|
24
|
+
locale_segment_proc: false
|
28
25
|
}.freeze
|
29
26
|
|
30
27
|
Configuration = Struct.new(*DEFAULT_CONFIGURATION.keys)
|
@@ -36,7 +33,7 @@ module RouteTranslator
|
|
36
33
|
@config.force_locale = false
|
37
34
|
@config.generate_unlocalized_routes = false
|
38
35
|
@config.generate_unnamed_unlocalized_routes = false
|
39
|
-
@config.hide_locale =
|
36
|
+
@config.hide_locale = true
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
@@ -33,8 +33,8 @@ module ActionDispatch
|
|
33
33
|
options: scope[:options] ? scope[:options].merge(translated_options) : translated_options
|
34
34
|
}
|
35
35
|
|
36
|
-
if RouteTranslator.config.
|
37
|
-
scope_params[:blocks].push RouteTranslator::
|
36
|
+
if RouteTranslator.config.host_locales.present?
|
37
|
+
scope_params[:blocks].push RouteTranslator::Host.lambdas_for_locale(locale)
|
38
38
|
end
|
39
39
|
|
40
40
|
::ActionDispatch::Routing::Mapper::Mapping.build scope_params, route_set, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, translated_options
|
@@ -5,20 +5,16 @@ module RouteTranslator
|
|
5
5
|
class << self
|
6
6
|
private
|
7
7
|
|
8
|
+
def lambdas
|
9
|
+
@lambdas ||= {}
|
10
|
+
end
|
11
|
+
|
8
12
|
def regex_for(host_string)
|
9
13
|
escaped = Regexp.escape(host_string).gsub('\*', '.*?').gsub('\.', '\.?')
|
10
14
|
Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def native_locale?(locale)
|
15
|
-
locale.to_s.include?('native_')
|
16
|
-
end
|
17
|
-
|
18
|
-
def native_locales
|
19
|
-
config.host_locales.values.map { |locale| :"native_#{locale}" }
|
20
|
-
end
|
21
|
-
|
22
18
|
module_function
|
23
19
|
|
24
20
|
def locale_from_host(host)
|
@@ -28,5 +24,9 @@ module RouteTranslator
|
|
28
24
|
locales &= I18n.available_locales
|
29
25
|
locales.first&.to_sym
|
30
26
|
end
|
27
|
+
|
28
|
+
def lambdas_for_locale(locale)
|
29
|
+
lambdas[locale] ||= ->(req) { locale == RouteTranslator::Host.locale_from_host(req.host) }
|
30
|
+
end
|
31
31
|
end
|
32
32
|
end
|
@@ -26,7 +26,7 @@ module RouteTranslator
|
|
26
26
|
translated_options = options.dup
|
27
27
|
|
28
28
|
if translated_options.exclude?(RouteTranslator.locale_param_key)
|
29
|
-
translated_options[RouteTranslator.locale_param_key] =
|
29
|
+
translated_options[RouteTranslator.locale_param_key] = locale.to_s
|
30
30
|
end
|
31
31
|
|
32
32
|
translated_options
|
@@ -53,7 +53,6 @@ module RouteTranslator
|
|
53
53
|
|
54
54
|
def available_locales
|
55
55
|
locales = RouteTranslator.available_locales
|
56
|
-
locales.concat(RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
|
57
56
|
# Make sure the default locale is translated in last place to avoid
|
58
57
|
# problems with wildcards when default locale is omitted in paths. The
|
59
58
|
# default routes will catch all paths like wildcard if it is translated first.
|
@@ -82,8 +81,6 @@ module RouteTranslator
|
|
82
81
|
|
83
82
|
locale = if args_locale
|
84
83
|
args_locale.to_s.underscore
|
85
|
-
elsif kaller.respond_to?("#{old_name}_native_#{current_locale_name}_#{suffix}")
|
86
|
-
"native_#{current_locale_name}"
|
87
84
|
elsif kaller.respond_to?("#{old_name}_#{current_locale_name}_#{suffix}")
|
88
85
|
current_locale_name
|
89
86
|
else
|
@@ -9,8 +9,7 @@ module RouteTranslator
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def display_locale?(locale)
|
12
|
-
!RouteTranslator.config.hide_locale && !
|
13
|
-
(!default_locale?(locale) || config_requires_locale?)
|
12
|
+
!RouteTranslator.config.hide_locale && (!default_locale?(locale) || config_requires_locale?)
|
14
13
|
end
|
15
14
|
|
16
15
|
def config_requires_locale?
|
@@ -32,8 +32,7 @@ module RouteTranslator
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def translate_string(str, locale, scope)
|
35
|
-
|
36
|
-
translated_resource = translate_resource(str, sanitized_locale, scope)
|
35
|
+
translated_resource = translate_resource(str, locale.to_s, scope)
|
37
36
|
|
38
37
|
Addressable::URI.normalize_component translated_resource
|
39
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 10.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geremia Taglialatela
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-01-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.20.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: 0.20.0
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: minitest
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,42 +168,70 @@ dependencies:
|
|
168
168
|
requirements:
|
169
169
|
- - "~>"
|
170
170
|
- !ruby/object:Gem::Version
|
171
|
-
version: 1.
|
171
|
+
version: '1.8'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - "~>"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '1.8'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: rubocop-minitest
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: 0.10.3
|
172
186
|
type: :development
|
173
187
|
prerelease: false
|
174
188
|
version_requirements: !ruby/object:Gem::Requirement
|
175
189
|
requirements:
|
176
190
|
- - "~>"
|
177
191
|
- !ruby/object:Gem::Version
|
178
|
-
version:
|
192
|
+
version: 0.10.3
|
179
193
|
- !ruby/object:Gem::Dependency
|
180
194
|
name: rubocop-performance
|
181
195
|
requirement: !ruby/object:Gem::Requirement
|
182
196
|
requirements:
|
183
197
|
- - "~>"
|
184
198
|
- !ruby/object:Gem::Version
|
185
|
-
version: '1.
|
199
|
+
version: '1.9'
|
186
200
|
type: :development
|
187
201
|
prerelease: false
|
188
202
|
version_requirements: !ruby/object:Gem::Requirement
|
189
203
|
requirements:
|
190
204
|
- - "~>"
|
191
205
|
- !ruby/object:Gem::Version
|
192
|
-
version: '1.
|
206
|
+
version: '1.9'
|
193
207
|
- !ruby/object:Gem::Dependency
|
194
208
|
name: rubocop-rails
|
195
209
|
requirement: !ruby/object:Gem::Requirement
|
196
210
|
requirements:
|
197
211
|
- - "~>"
|
198
212
|
- !ruby/object:Gem::Version
|
199
|
-
version: '2.
|
213
|
+
version: '2.9'
|
214
|
+
type: :development
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - "~>"
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '2.9'
|
221
|
+
- !ruby/object:Gem::Dependency
|
222
|
+
name: rubocop-rake
|
223
|
+
requirement: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - "~>"
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: 0.5.1
|
200
228
|
type: :development
|
201
229
|
prerelease: false
|
202
230
|
version_requirements: !ruby/object:Gem::Requirement
|
203
231
|
requirements:
|
204
232
|
- - "~>"
|
205
233
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
234
|
+
version: 0.5.1
|
207
235
|
- !ruby/object:Gem::Dependency
|
208
236
|
name: simplecov
|
209
237
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,7 +241,7 @@ dependencies:
|
|
213
241
|
version: 0.18.5
|
214
242
|
- - "<"
|
215
243
|
- !ruby/object:Gem::Version
|
216
|
-
version: '0.
|
244
|
+
version: '0.22'
|
217
245
|
type: :development
|
218
246
|
prerelease: false
|
219
247
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -223,7 +251,7 @@ dependencies:
|
|
223
251
|
version: 0.18.5
|
224
252
|
- - "<"
|
225
253
|
- !ruby/object:Gem::Version
|
226
|
-
version: '0.
|
254
|
+
version: '0.22'
|
227
255
|
description: Translates the Rails routes of your application into the languages defined
|
228
256
|
in your locale files
|
229
257
|
email:
|
@@ -243,8 +271,6 @@ files:
|
|
243
271
|
- lib/route_translator/extensions/route_set.rb
|
244
272
|
- lib/route_translator/extensions/test_case.rb
|
245
273
|
- lib/route_translator/host.rb
|
246
|
-
- lib/route_translator/host_path_consistency_lambdas.rb
|
247
|
-
- lib/route_translator/locale_sanitizer.rb
|
248
274
|
- lib/route_translator/route.rb
|
249
275
|
- lib/route_translator/translator.rb
|
250
276
|
- lib/route_translator/translator/path.rb
|
@@ -273,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
299
|
- !ruby/object:Gem::Version
|
274
300
|
version: '0'
|
275
301
|
requirements: []
|
276
|
-
rubygems_version: 3.
|
302
|
+
rubygems_version: 3.2.3
|
277
303
|
signing_key:
|
278
304
|
specification_version: 4
|
279
305
|
summary: Translate your Rails routes in a simple manner
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RouteTranslator
|
4
|
-
module HostPathConsistencyLambdas
|
5
|
-
class << self
|
6
|
-
private
|
7
|
-
|
8
|
-
def lambdas
|
9
|
-
@lambdas ||= {}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module_function
|
14
|
-
|
15
|
-
def for_locale(locale)
|
16
|
-
sanitized_locale = RouteTranslator::LocaleSanitizer.sanitize(locale)
|
17
|
-
|
18
|
-
lambdas[sanitized_locale] ||= ->(req) { sanitized_locale == RouteTranslator::Host.locale_from_host(req.host).to_s }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|