route_translator 4.2.2 → 4.2.3
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0245ec3dc888fe4075acdc5b7f75a83abc484315
|
4
|
+
data.tar.gz: 830fe48ec660d44d6f41611addc896c917fc6e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3887741389738e173cd52b317bc81f463c42c640ae255d4f85e48dcb4fccf17ee06baa6543a265a9d35dbe9848fffb24fdd97d4f7e7ac3854a465e678f16db3
|
7
|
+
data.tar.gz: 0411af88304f09a2005960c0d24699d50a8e2a5a24b1b55895336ca0ef09790082749bd7aacbeca46e059d6515e74fe3a37dc390fc5a95c9e2374688f7b25356
|
data/CHANGELOG.md
CHANGED
data/lib/route_translator.rb
CHANGED
@@ -7,7 +7,7 @@ require File.expand_path('../route_translator/host', __FILE__)
|
|
7
7
|
module RouteTranslator
|
8
8
|
extend RouteTranslator::Host
|
9
9
|
|
10
|
-
TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()
|
10
|
+
TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()?/
|
11
11
|
|
12
12
|
Configuration = Struct.new(:force_locale, :hide_locale,
|
13
13
|
:generate_unlocalized_routes, :locale_param_key,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'action_dispatch'
|
2
3
|
|
3
4
|
module ActionDispatch
|
@@ -9,46 +10,31 @@ module ActionDispatch
|
|
9
10
|
@localized = false
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
path = path_for_action(action, options.delete(:path))
|
13
|
+
def add_route(action, options) # :nodoc:
|
14
|
+
path = path_for_action(action, options.delete(:path))
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if !options.fetch(:as, true)
|
23
|
-
options.delete(:as)
|
24
|
-
else
|
25
|
-
options[:as] = name_for_action(options[:as], action)
|
26
|
-
end
|
16
|
+
if action.to_s =~ %r{^[\w\/]+$}
|
17
|
+
options[:action] ||= action unless action.to_s.include?('/'.freeze)
|
18
|
+
else
|
19
|
+
action = nil
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
if !options.fetch(:as, true)
|
23
|
+
options.delete(:as)
|
24
|
+
else
|
25
|
+
options[:as] = name_for_action(options[:as], action)
|
26
|
+
end
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
28
|
+
begin
|
29
|
+
mapping = Mapping.new(@set, @scope, path, options)
|
30
|
+
rescue ArgumentError
|
31
|
+
mapping = Mapping.build(@scope, @set, URI.parser.escape(path), options.delete(:as), options)
|
39
32
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if @localized
|
46
|
-
@set.add_localized_route(app, conditions, requirements, defaults, as, anchor)
|
47
|
-
else
|
48
|
-
@set.add_route(app, conditions, requirements, defaults, as, anchor)
|
49
|
-
end
|
50
|
-
self
|
51
|
-
end
|
33
|
+
|
34
|
+
if @localized
|
35
|
+
@set.add_localized_route(*mapping.to_route)
|
36
|
+
else
|
37
|
+
@set.add_route(*mapping.to_route)
|
52
38
|
end
|
53
39
|
end
|
54
40
|
end
|
@@ -7,6 +7,12 @@ module ActionDispatch
|
|
7
7
|
RouteTranslator::Translator.translations_for(app, conditions, requirements, defaults, as, anchor, self) do |*translated_args|
|
8
8
|
add_route(*translated_args)
|
9
9
|
end
|
10
|
+
|
11
|
+
if RouteTranslator.config.generate_unnamed_unlocalized_routes
|
12
|
+
add_route app, conditions, requirements, defaults, nil, anchor
|
13
|
+
elsif RouteTranslator.config.generate_unlocalized_routes
|
14
|
+
add_route app, conditions, requirements, defaults, as, anchor
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module RouteTranslator
|
2
3
|
module Translator
|
3
4
|
# Add standard route helpers for default locale e.g.
|
@@ -58,15 +59,8 @@ module RouteTranslator
|
|
58
59
|
new_route_name = nil if new_route_name && route_set.named_routes.routes[new_route_name.to_sym] # TODO: Investigate this :(
|
59
60
|
block.call(app, new_conditions, new_requirements, new_defaults, new_route_name, anchor)
|
60
61
|
end
|
61
|
-
if RouteTranslator.config.generate_unnamed_unlocalized_routes
|
62
|
-
block.call(app, conditions, requirements, defaults, nil, anchor)
|
63
|
-
elsif RouteTranslator.config.generate_unlocalized_routes
|
64
|
-
block.call(app, conditions, requirements, defaults, route_name, anchor)
|
65
|
-
end
|
66
62
|
end
|
67
63
|
|
68
|
-
private
|
69
|
-
|
70
64
|
def self.available_locales
|
71
65
|
available_locales = config_locales || I18n.available_locales.dup
|
72
66
|
available_locales.push(*RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
|
@@ -134,7 +128,7 @@ module RouteTranslator
|
|
134
128
|
end
|
135
129
|
|
136
130
|
def self.translate_string(str, locale)
|
137
|
-
locale =
|
131
|
+
locale = locale.to_s.gsub('native_', '')
|
138
132
|
opts = { scope: :routes, locale: locale }
|
139
133
|
if RouteTranslator.config.disable_fallback && locale.to_s != I18n.default_locale.to_s
|
140
134
|
opts[:fallback] = true
|
@@ -146,7 +140,7 @@ module RouteTranslator
|
|
146
140
|
end
|
147
141
|
|
148
142
|
def self.locale_param_present?(path)
|
149
|
-
!
|
143
|
+
!path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key}" }.nil?
|
150
144
|
end
|
151
145
|
|
152
146
|
def self.host_locales_option?
|
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.2.
|
4
|
+
version: 4.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raul Murciano
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -125,14 +125,14 @@ dependencies:
|
|
125
125
|
requirements:
|
126
126
|
- - "~>"
|
127
127
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
128
|
+
version: 0.36.0
|
129
129
|
type: :development
|
130
130
|
prerelease: false
|
131
131
|
version_requirements: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
133
|
- - "~>"
|
134
134
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
135
|
+
version: 0.36.0
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: simplecov
|
138
138
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.4.
|
188
|
+
rubygems_version: 2.4.3
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Translate your Rails routes in a simple manner
|