route_translator 16.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a47bd0c7cfd26fdd5874b1bfd7c56236c4c371f9ba21387256f8e95ee6942dc7
4
- data.tar.gz: fd3faf20805afd09e770705d8110612e1c7d68de652149a3bfb38ddd179d035d
3
+ metadata.gz: 23d51c2f3daa3a386392bb17635f909e39bc47b9eb99b05855e1b797d1526c78
4
+ data.tar.gz: 4aed689835518bb310417891d40b8f815eebd187d2963c1de9a9bd85d11ef092
5
5
  SHA512:
6
- metadata.gz: 4e5c88d328fdf31d1cc173c92d4d2c5a95048f1ba2d6113e9845a992b1263f2ce47e71b706192a24485dc49257a3f38a5c225b0176af95a5fed78c56a14d4018
7
- data.tar.gz: 72b6b0f9613be540c41f1fe7570c0e5773e870a929c33783d9762a7122a2f530f01a8d49d7abc778e821d601fea697cf9813a07b0c7858638687a1317b03e6a4
6
+ metadata.gz: 25e0947dc9da22d3806fbbfa46efdc6cfaeba6261ba2124b93279674212f92dc6f8af68a06faae538f37ac5442d387b7be86f3d51d312802401fb27d7bf70d65
7
+ data.tar.gz: dcdc6fd21ff2aa6d9eab67b437f051d58b8e6cb4535f853192abf0594c725cc7ed6b09bfcfaec28d0d58cea4b774826af6a4d48aac1ef2c6dfb99d149d7fb9cf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## 16.0.1 / 2026-04-05
4
9
 
5
10
  * [ENHANCEMENT] Optimize host locale detection ([#354](https://github.com/enriclluelles/route_translator/pull/354))
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` | Add the behavior of `force_locale`, but with a named default route which behaves as if `generate_unlocalized_routes` was `true`. `root_path` will redirect to `/en` or `/es`, depending on the value of `I18n.locale` | `false` |
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` |
@@ -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, named_routes_names)
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 if named_routes_names.exclude?(translated_name.to_sym)
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.names)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RouteTranslator
4
- VERSION = '16.0.1'
4
+ VERSION = '16.1.0'
5
5
  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: 16.0.1
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.9
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: []