route_translator 16.0.0 → 16.1.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 +9 -0
- data/README.md +1 -1
- data/lib/route_translator/host.rb +1 -1
- data/lib/route_translator/translator/route_helpers.rb +0 -4
- data/lib/route_translator/translator.rb +3 -3
- data/lib/route_translator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23d51c2f3daa3a386392bb17635f909e39bc47b9eb99b05855e1b797d1526c78
|
|
4
|
+
data.tar.gz: 4aed689835518bb310417891d40b8f815eebd187d2963c1de9a9bd85d11ef092
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25e0947dc9da22d3806fbbfa46efdc6cfaeba6261ba2124b93279674212f92dc6f8af68a06faae538f37ac5442d387b7be86f3d51d312802401fb27d7bf70d65
|
|
7
|
+
data.tar.gz: dcdc6fd21ff2aa6d9eab67b437f051d58b8e6cb4535f853192abf0594c725cc7ed6b09bfcfaec28d0d58cea4b774826af6a4d48aac1ef2c6dfb99d149d7fb9cf
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 16.1.0 / 2026-07-28
|
|
4
|
+
|
|
5
|
+
* [ENHANCEMENT] Speed up drawing localized routes. `Translator.translate_name` asked the route set for `named_routes.names` (a freshly allocated array of every name defined so far) and scanned it linearly, once per route per locale. It now uses the `NamedRouteCollection#key?` hash lookup.
|
|
6
|
+
* [ENHANCEMENT] Speed up drawing localized routes. `Translator::RouteHelpers.add` fetched `named_route_collection.helper_names` on every route, allocating an array of every helper defined so far and scanning it, to guard a `push` that could not take effect. `helper_names` builds a fresh array on every call, so the push was discarded, and it returns Strings while the pushed value is a Symbol, so the `include?` guard never matched either. Removing both leaves behavior unchanged.
|
|
7
|
+
|
|
8
|
+
## 16.0.1 / 2026-04-05
|
|
9
|
+
|
|
10
|
+
* [ENHANCEMENT] Optimize host locale detection ([#354](https://github.com/enriclluelles/route_translator/pull/354))
|
|
11
|
+
|
|
3
12
|
## 16.0.0 / 2026-03-18
|
|
4
13
|
|
|
5
14
|
* [FEATURE] Drop Ruby < 3.2 support
|
data/README.md
CHANGED
|
@@ -273,7 +273,7 @@ end
|
|
|
273
273
|
| `disable_fallback` | Create routes only for locales that have translations. For example, if we have `/examples` and a translation is not provided for `es`, the route helper of `examples_es` will not be created. Useful when one uses this with a locale route constraint, so non-`es` routes can return a `404` on a Spanish website | `false` |
|
|
274
274
|
| `force_locale` | Force the locale to be added to all generated route paths, even for the default locale | `false` |
|
|
275
275
|
| `generate_unlocalized_routes` | Add translated routes without deleting original unlocalized versions. **Note:** Autosets `force_locale` to `true` | `false` |
|
|
276
|
-
| `generate_unnamed_unlocalized_routes` |
|
|
276
|
+
| `generate_unnamed_unlocalized_routes` | Adds per-locale named routes plus the original unlocalized mapping as an unnamed action route; it does not redirect. Like `force_locale`, it still shows the locale segment even for the default locale (for example, `/en/...`). Flat helpers (`people_path`) still dispatch to the per-locale variant via `I18n.locale`. Safe for legacy bare paths; avoid in multi-locale SEO setups unless you handle canonical URLs or redirects yourself, since both bare and locale-prefixed paths serve the same action. See [#110](https://github.com/enriclluelles/route_translator/issues/110) | `false` |
|
|
277
277
|
| `hide_locale` | Force the locale to be hidden on generated route paths | `false` |
|
|
278
278
|
| `host_locales` | Set `I18n.locale` based on `request.host`. Useful for apps accepting requests from more than one domain. The key is a host pattern (supports wildcards for domains, subdomains, and TLDs), and the value is the locale symbol or string to use. See below for more details and examples. | `{}` |
|
|
279
279
|
| `locale_param_key` | The param key used to set the locale to the newly generated routes | `:locale` |
|
|
@@ -10,7 +10,7 @@ module RouteTranslator
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def regex_for(host_string)
|
|
13
|
-
escaped = Regexp.escape(host_string).gsub('
|
|
13
|
+
escaped = Regexp.escape(host_string).gsub(/\\\*|\\\./, '\\*' => '.*?', '\\.' => '\.?')
|
|
14
14
|
Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -15,14 +15,10 @@ module RouteTranslator
|
|
|
15
15
|
# I18n.locale = :fr
|
|
16
16
|
# people_path -> people_fr_path
|
|
17
17
|
def add(old_name, named_route_collection)
|
|
18
|
-
helper_list = named_route_collection.helper_names
|
|
19
|
-
|
|
20
18
|
%w[path url].each do |suffix|
|
|
21
19
|
helper_container = named_route_collection.send(:"#{suffix}_helpers_module")
|
|
22
20
|
new_helper_name = :"#{old_name}_#{suffix}"
|
|
23
21
|
|
|
24
|
-
helper_list.push(new_helper_name) unless helper_list.include?(new_helper_name)
|
|
25
|
-
|
|
26
22
|
helper_container.__send__(:define_method, new_helper_name) do |*args|
|
|
27
23
|
__send__(Translator.route_name_for(args, old_name, suffix, self), *args)
|
|
28
24
|
end
|
|
@@ -14,12 +14,12 @@ module RouteTranslator
|
|
|
14
14
|
args_hash&.fetch(:locale, nil)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def translate_name(name, locale,
|
|
17
|
+
def translate_name(name, locale, named_routes)
|
|
18
18
|
return if name.blank?
|
|
19
19
|
|
|
20
20
|
translated_name = "#{name}_#{locale.to_s.underscore}"
|
|
21
21
|
|
|
22
|
-
translated_name
|
|
22
|
+
translated_name unless named_routes.key?(translated_name)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def translate_options(options, locale)
|
|
@@ -67,7 +67,7 @@ module RouteTranslator
|
|
|
67
67
|
translated_path = translate_path(route.path, locale, route.scope)
|
|
68
68
|
next unless translated_path
|
|
69
69
|
|
|
70
|
-
translated_name = translate_name(route.name, locale, route.route_set.named_routes
|
|
70
|
+
translated_name = translate_name(route.name, locale, route.route_set.named_routes)
|
|
71
71
|
translated_options_constraints = translate_options_constraints(route.options_constraints, locale)
|
|
72
72
|
translated_options = translate_options(route.options, locale)
|
|
73
73
|
|
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: 16.
|
|
4
|
+
version: 16.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Geremia Taglialatela
|
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
90
|
- !ruby/object:Gem::Version
|
|
91
91
|
version: '0'
|
|
92
92
|
requirements: []
|
|
93
|
-
rubygems_version: 4.0.
|
|
93
|
+
rubygems_version: 4.0.16
|
|
94
94
|
specification_version: 4
|
|
95
95
|
summary: Translate your Rails routes in a simple manner
|
|
96
96
|
test_files: []
|