route_translator 15.1.0 → 15.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/route_translator/extensions/legacy/mapper.rb +55 -0
- data/lib/route_translator/extensions/legacy/route_set.rb +42 -0
- data/lib/route_translator/extensions/mapper.rb +8 -15
- data/lib/route_translator/extensions/route_set.rb +5 -7
- data/lib/route_translator/extensions.rb +11 -2
- data/lib/route_translator/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13e7ca36c52b904acf706a63b2cc0b352ed0206010b69dbf65eba016ab2fefdb
|
4
|
+
data.tar.gz: 6721c17d101b7528a9a603ff196c0fabdc49d4b0ca54a42e3b842213ef585ead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4837bc35c697c191a1219d42c5e8a6a05241aaa2cce847dfee6e000acfb460335b6007c1d499c1a049ece53cbff466a3647385e1a5b85c8ff9e6b65f7da98cbc
|
7
|
+
data.tar.gz: 2fe7754133ec168a03208316f98ea24696700dc03766d9b86bbbee25785e77f85d0445f82fedebc45fd43a8b51f4fc28bbae57d817d0f1bb206a0bc0b82fcb9b
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 15.2.0 / 2025-07-06
|
4
|
+
|
5
|
+
* [FEATURE] Rails 8.1 edge support ([#344](https://github.com/enriclluelles/route_translator/pull/344))
|
6
|
+
|
3
7
|
## 15.1.0 / 2025-06-15
|
4
8
|
|
5
9
|
* [BUGFIX] Ensure `@localized` is always reset after yield ([#333](https://github.com/enriclluelles/route_translator/issues/333))
|
6
10
|
* [ENHANCEMENT] Optimize host locale detection ([#337](https://github.com/enriclluelles/route_translator/pull/337))
|
7
|
-
* [ENHANCEMENT] Add `locale_from_request` method ([#
|
11
|
+
* [ENHANCEMENT] Add `locale_from_request` method ([#340](https://github.com/enriclluelles/route_translator/pull/340))
|
8
12
|
|
9
13
|
## 15.0.0 / 2025-06-12
|
10
14
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
module Routing
|
5
|
+
class Mapper
|
6
|
+
def localized
|
7
|
+
@localized = true
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
@localized = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# rubocop:disable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
|
14
|
+
def add_route(action, controller, options, _path, to, via, formatted, anchor, options_constraints) # :nodoc:
|
15
|
+
return super unless @localized
|
16
|
+
|
17
|
+
path = path_for_action(action, _path)
|
18
|
+
raise ArgumentError, 'path is required' if path.blank?
|
19
|
+
|
20
|
+
action = action.to_s
|
21
|
+
|
22
|
+
default_action = options.delete(:action) || @scope[:action]
|
23
|
+
|
24
|
+
if %r{^[\w\-\/]+$}.match?(action)
|
25
|
+
default_action ||= action.tr('-', '_') unless action.include?('/')
|
26
|
+
else
|
27
|
+
action = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
as = if options.fetch(:as, true)
|
31
|
+
name_for_action(options.delete(:as), action)
|
32
|
+
else
|
33
|
+
options.delete(:as)
|
34
|
+
end
|
35
|
+
|
36
|
+
path = Mapping.normalize_path URI::DEFAULT_PARSER.escape(path), formatted
|
37
|
+
ast = Journey::Parser.parse path
|
38
|
+
|
39
|
+
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
|
40
|
+
@set.add_localized_route(mapping, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options)
|
41
|
+
end
|
42
|
+
# rubocop:enable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def define_generate_prefix(app, name)
|
47
|
+
return super unless @localized
|
48
|
+
|
49
|
+
RouteTranslator::Translator.available_locales.each do |locale|
|
50
|
+
super(app, "#{name}_#{locale.to_s.underscore}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
module Routing
|
5
|
+
class RouteSet
|
6
|
+
def add_localized_route(mapping, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, options)
|
7
|
+
route = RouteTranslator::Route.new(self, path, name, options_constraints, options, mapping)
|
8
|
+
|
9
|
+
RouteTranslator::Translator.translations_for(route) do |locale, translated_name, translated_path, translated_options_constraints, translated_options|
|
10
|
+
translated_path_ast = ::ActionDispatch::Journey::Parser.parse(translated_path)
|
11
|
+
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
12
|
+
|
13
|
+
add_route translated_mapping, translated_name
|
14
|
+
end
|
15
|
+
|
16
|
+
if RouteTranslator.config.generate_unnamed_unlocalized_routes
|
17
|
+
add_route mapping, nil
|
18
|
+
elsif RouteTranslator.config.generate_unlocalized_routes
|
19
|
+
add_route mapping, name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
26
|
+
scope_params = {
|
27
|
+
blocks: (scope[:blocks] || []).dup,
|
28
|
+
constraints: scope[:constraints] || {},
|
29
|
+
defaults: scope[:defaults] || {},
|
30
|
+
module: scope[:module],
|
31
|
+
options: scope[:options] ? scope[:options].merge(translated_options) : translated_options
|
32
|
+
}
|
33
|
+
|
34
|
+
if RouteTranslator.config.host_locales.present?
|
35
|
+
scope_params[:blocks].push RouteTranslator::Host.lambdas_for_locale(locale)
|
36
|
+
end
|
37
|
+
|
38
|
+
::ActionDispatch::Routing::Mapper::Mapping.build scope_params, route_set, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, translated_options
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'action_dispatch'
|
4
|
-
|
5
3
|
module ActionDispatch
|
6
4
|
module Routing
|
7
5
|
class Mapper
|
@@ -13,7 +11,7 @@ module ActionDispatch
|
|
13
11
|
end
|
14
12
|
|
15
13
|
# rubocop:disable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
|
16
|
-
def add_route(action, controller,
|
14
|
+
def add_route(action, controller, as, options_action, _path, to, via, formatted, anchor, options_constraints, internal, options_mapping) # :nodoc:
|
17
15
|
return super unless @localized
|
18
16
|
|
19
17
|
path = path_for_action(action, _path)
|
@@ -21,25 +19,20 @@ module ActionDispatch
|
|
21
19
|
|
22
20
|
action = action.to_s
|
23
21
|
|
24
|
-
default_action =
|
22
|
+
default_action = options_action || @scope[:action]
|
25
23
|
|
26
|
-
if %r{^[\w
|
24
|
+
if %r{^[\w\-/]+$}.match?(action)
|
27
25
|
default_action ||= action.tr('-', '_') unless action.include?('/')
|
28
26
|
else
|
29
27
|
action = nil
|
30
28
|
end
|
31
29
|
|
32
|
-
as
|
33
|
-
|
34
|
-
|
35
|
-
options.delete(:as)
|
36
|
-
end
|
37
|
-
|
38
|
-
path = Mapping.normalize_path URI::DEFAULT_PARSER.escape(path), formatted
|
39
|
-
ast = Journey::Parser.parse path
|
30
|
+
as = name_for_action(as, action) if as
|
31
|
+
path = Mapping.normalize_path URI::RFC2396_PARSER.escape(path), formatted
|
32
|
+
ast = Journey::Parser.parse path
|
40
33
|
|
41
|
-
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor,
|
42
|
-
@set.add_localized_route(mapping, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints,
|
34
|
+
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, internal, options_mapping)
|
35
|
+
@set.add_localized_route(mapping, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, internal, options_mapping)
|
43
36
|
end
|
44
37
|
# rubocop:enable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
|
45
38
|
|
@@ -1,16 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'action_dispatch'
|
4
|
-
|
5
3
|
module ActionDispatch
|
6
4
|
module Routing
|
7
5
|
class RouteSet
|
8
|
-
def add_localized_route(mapping, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints,
|
9
|
-
route = RouteTranslator::Route.new(self, path, name, options_constraints,
|
6
|
+
def add_localized_route(mapping, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, internal, options_mapping)
|
7
|
+
route = RouteTranslator::Route.new(self, path, name, options_constraints, options_mapping, mapping)
|
10
8
|
|
11
9
|
RouteTranslator::Translator.translations_for(route) do |locale, translated_name, translated_path, translated_options_constraints, translated_options|
|
12
10
|
translated_path_ast = ::ActionDispatch::Journey::Parser.parse(translated_path)
|
13
|
-
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
11
|
+
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor, internal)
|
14
12
|
|
15
13
|
add_route translated_mapping, translated_name
|
16
14
|
end
|
@@ -24,7 +22,7 @@ module ActionDispatch
|
|
24
22
|
|
25
23
|
private
|
26
24
|
|
27
|
-
def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
|
25
|
+
def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor, internal)
|
28
26
|
scope_params = {
|
29
27
|
blocks: (scope[:blocks] || []).dup,
|
30
28
|
constraints: scope[:constraints] || {},
|
@@ -37,7 +35,7 @@ module ActionDispatch
|
|
37
35
|
scope_params[:blocks].push RouteTranslator::Host.lambdas_for_locale(locale)
|
38
36
|
end
|
39
37
|
|
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
|
38
|
+
::ActionDispatch::Routing::Mapper::Mapping.build scope_params, route_set, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, internal, translated_options
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -1,5 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'action_dispatch'
|
4
|
+
|
5
|
+
# TODO: Remove `else` branch when dropping Rails < 8.1 support
|
6
|
+
if ActionDispatch::Routing::Mapper.instance_method(:add_route).arity == 12
|
7
|
+
require_relative 'extensions/mapper'
|
8
|
+
require_relative 'extensions/route_set'
|
9
|
+
else
|
10
|
+
require_relative 'extensions/legacy/mapper'
|
11
|
+
require_relative 'extensions/legacy/route_set'
|
12
|
+
end
|
13
|
+
|
5
14
|
require_relative 'extensions/action_controller'
|
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: 15.
|
4
|
+
version: 15.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geremia Taglialatela
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- lib/route_translator.rb
|
57
57
|
- lib/route_translator/extensions.rb
|
58
58
|
- lib/route_translator/extensions/action_controller.rb
|
59
|
+
- lib/route_translator/extensions/legacy/mapper.rb
|
60
|
+
- lib/route_translator/extensions/legacy/route_set.rb
|
59
61
|
- lib/route_translator/extensions/mapper.rb
|
60
62
|
- lib/route_translator/extensions/route_set.rb
|
61
63
|
- lib/route_translator/extensions/test_case.rb
|