route_translator 5.4.1 → 5.5.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 +5 -0
- data/README.md +4 -1
- data/lib/route_translator.rb +7 -4
- data/lib/route_translator/extensions.rb +3 -3
- data/lib/route_translator/extensions/route_set.rb +17 -2
- data/lib/route_translator/host_path_consistency_lambdas.rb +21 -0
- data/lib/route_translator/locale_sanitizer.rb +11 -0
- data/lib/route_translator/translator.rb +5 -5
- data/lib/route_translator/translator/path.rb +1 -1
- data/lib/route_translator/translator/path/segment.rb +2 -2
- data/lib/route_translator/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31c45f4f07f63d37b9cdcf3d3d03e4fa1b59c2dd
|
4
|
+
data.tar.gz: 6ef546c5332a49738627d17945dc4885d27ff0d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db0724276af9860e0625f4658c5ed52cf8636e4367d6238f0386ac3bfa4cd9d94fcc51021cb171916f3d3887ed893cba4c445b4964e3e39bedb651437926614
|
7
|
+
data.tar.gz: a0d0a239715a71ac417ebfaef82be0cbfa32ad0042afdcd45d22dd4fe434ef9bbf18002104f531a46a06eaa4a1d0ee39fd4e9533ec7ce0f89cb4990d6c6b8c6a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -284,7 +284,10 @@ end
|
|
284
284
|
* **locale_segment_proc**
|
285
285
|
The locale segment of the url will by default be `locale.to_s.downcase`
|
286
286
|
You can supply your own mechanism via a Proc that takes `locale` as an argument, e.g. `config.locale_segment_proc = ->(locale) { locale.to_s.upcase }`
|
287
|
-
|
287
|
+
* **verify_host_path_consistency**
|
288
|
+
By default, if you use different hosts to translate your application, all translated paths will work on all hosts. Set this option to `true` to force
|
289
|
+
a matching of the host associated locale with the translated path locale as part of the route definition.
|
290
|
+
Defaults to `false`.
|
288
291
|
|
289
292
|
### Host-based Locale
|
290
293
|
|
data/lib/route_translator.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'active_support'
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require 'route_translator/extensions'
|
6
|
+
require 'route_translator/translator'
|
7
|
+
require 'route_translator/host'
|
8
|
+
require 'route_translator/host_path_consistency_lambdas'
|
9
|
+
require 'route_translator/locale_sanitizer'
|
8
10
|
|
9
11
|
module RouteTranslator
|
10
12
|
extend RouteTranslator::Host
|
@@ -14,7 +16,7 @@ module RouteTranslator
|
|
14
16
|
Configuration = Struct.new(:available_locales, :disable_fallback, :force_locale,
|
15
17
|
:hide_locale, :host_locales, :generate_unlocalized_routes,
|
16
18
|
:generate_unnamed_unlocalized_routes, :locale_param_key,
|
17
|
-
:locale_segment_proc)
|
19
|
+
:locale_segment_proc, :verify_host_path_consistency)
|
18
20
|
|
19
21
|
class << self
|
20
22
|
private
|
@@ -40,6 +42,7 @@ module RouteTranslator
|
|
40
42
|
@config.generate_unnamed_unlocalized_routes ||= false
|
41
43
|
@config.locale_param_key ||= :locale
|
42
44
|
@config.locale_segment_proc ||= nil
|
45
|
+
@config.verify_host_path_consistency ||= false
|
43
46
|
|
44
47
|
yield @config if block
|
45
48
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'route_translator/extensions/mapper'
|
4
|
+
require 'route_translator/extensions/route_set'
|
5
|
+
require 'route_translator/extensions/action_controller'
|
@@ -8,9 +8,9 @@ module ActionDispatch
|
|
8
8
|
def add_localized_route(mapping, path_ast, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, options)
|
9
9
|
route = RouteTranslator::Route.new(self, path, name, options_constraints, options, mapping)
|
10
10
|
|
11
|
-
RouteTranslator::Translator.translations_for(route) do |translated_name, translated_path, translated_options_constraints, translated_options|
|
11
|
+
RouteTranslator::Translator.translations_for(route) do |locale, translated_name, translated_path, translated_options_constraints, translated_options|
|
12
12
|
translated_path_ast = ::ActionDispatch::Journey::Parser.parse(translated_path)
|
13
|
-
translated_mapping =
|
13
|
+
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
14
14
|
|
15
15
|
add_route_to_set translated_mapping, translated_path_ast, translated_name, anchor
|
16
16
|
end
|
@@ -24,6 +24,21 @@ module ActionDispatch
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
28
|
+
options = scope[:options] ? scope[:options].merge(translated_options) : translated_options
|
29
|
+
|
30
|
+
defaults = (scope[:defaults] || {}).dup
|
31
|
+
scope_constraints = scope[:constraints] || {}
|
32
|
+
|
33
|
+
blocks = scope[:blocks] ? scope[:blocks].dup : []
|
34
|
+
|
35
|
+
if RouteTranslator.config.verify_host_path_consistency
|
36
|
+
blocks.push RouteTranslator::HostPathConsistencyLambdas.for_locale(locale)
|
37
|
+
end
|
38
|
+
|
39
|
+
::ActionDispatch::Routing::Mapper::Mapping.new(route_set, translated_path_ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, blocks, via, translated_options_constraints, anchor, options)
|
40
|
+
end
|
41
|
+
|
27
42
|
def add_route_to_set(mapping, path_ast, name, anchor)
|
28
43
|
if method(:add_route).arity == 4
|
29
44
|
add_route mapping, path_ast, name, anchor
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'route_translator/translator/route_helpers'
|
4
|
+
require 'route_translator/translator/path'
|
5
|
+
require 'route_translator/route'
|
6
6
|
|
7
7
|
module RouteTranslator
|
8
8
|
module Translator
|
@@ -25,7 +25,7 @@ module RouteTranslator
|
|
25
25
|
translated_options = options.dup
|
26
26
|
|
27
27
|
if translated_options.exclude?(RouteTranslator.locale_param_key)
|
28
|
-
translated_options[RouteTranslator.locale_param_key] =
|
28
|
+
translated_options[RouteTranslator.locale_param_key] = RouteTranslator::LocaleSanitizer.sanitize(locale)
|
29
29
|
end
|
30
30
|
|
31
31
|
translated_options
|
@@ -71,7 +71,7 @@ module RouteTranslator
|
|
71
71
|
translated_options_constraints = translate_options_constraints(route.options_constraints, locale)
|
72
72
|
translated_options = translate_options(route.options, locale)
|
73
73
|
|
74
|
-
yield translated_name, translated_path, translated_options_constraints, translated_options
|
74
|
+
yield locale, translated_name, translated_path, translated_options_constraints, translated_options
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -32,8 +32,8 @@ module RouteTranslator
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def translate_string(str, locale, scope)
|
35
|
-
|
36
|
-
translated_resource = translate_resource(str,
|
35
|
+
sanitized_locale = RouteTranslator::LocaleSanitizer.sanitize(locale)
|
36
|
+
translated_resource = translate_resource(str, sanitized_locale, scope)
|
37
37
|
|
38
38
|
URI.escape translated_resource
|
39
39
|
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: 5.
|
4
|
+
version: 5.5.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: 2017-06-
|
13
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -188,6 +188,8 @@ files:
|
|
188
188
|
- lib/route_translator/extensions/mapper.rb
|
189
189
|
- lib/route_translator/extensions/route_set.rb
|
190
190
|
- lib/route_translator/host.rb
|
191
|
+
- lib/route_translator/host_path_consistency_lambdas.rb
|
192
|
+
- lib/route_translator/locale_sanitizer.rb
|
191
193
|
- lib/route_translator/route.rb
|
192
194
|
- lib/route_translator/translator.rb
|
193
195
|
- lib/route_translator/translator/path.rb
|