route_translator 13.2.1 → 14.0.1

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
  SHA256:
3
- metadata.gz: b6fce16b25f253c530a462e14251479236768723b507359e93db129274ab14ae
4
- data.tar.gz: 0fb41bf9534c717748acc18bd61213998a3648b7808b20ced17132694f84f135
3
+ metadata.gz: 7fcad9eea1b8f21a0cd9f080b7d265e99e506832b36e841e73269f32f8889fe4
4
+ data.tar.gz: b56954aecf4c3bf8b4f0574f85902cf3b4a39e479732ad9f0d9115db4ee1026e
5
5
  SHA512:
6
- metadata.gz: 067e8efc0ef38001c0dee08bf2b7640f497edf0f69448448a0c596b63ac32c0110f906160d2fe34991d0c9f50895ef0f775e903f382c54748fedfae6de8df6eb
7
- data.tar.gz: b5b62f4644dc3fd6ad6401927ce4af0b897572467d86ffaabb444254680e9adaf97194a2c3cc17b6bf9abdfdad1213bd350ddeb73c5e9c242c53baef93590387
6
+ metadata.gz: 86e095fd11dc008b616056bfcfc2af1a49e61d0326422b4c54e7bd6bba158efea335fdc9d852c0dc888c93049956f0fdd5abd1d61f30b35efcd7c2b90887707a
7
+ data.tar.gz: 11e1ce6b4304f48afd72903cdf9192cec31e7b3142ba715ae9192821aac9a70acc8344b5c1914f8b7efe59b1b33146502dad300bd3429ad5a09cfa46605bd073
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 14.0.1 / 2023-09-03
4
+
5
+ * [BUGFIX] Fix eager load on booting ([#296](https://github.com/enriclluelles/route_translator/issues/296))
6
+
7
+ ## 14.0.0 / 2023-09-02
8
+
9
+ * [FEATURE] BREAKING CHANGE: Force standard nested separator (Upgrade guide at [#285](https://github.com/enriclluelles/route_translator/pull/285))
10
+ * [FEATURE] Drop Ruby 2.6 compatibility
11
+ * [FEATURE] Drop Rails < 6.1 compatibility
12
+ * [FEATURE] Add initializer generator
13
+ * [ENHANCEMENT] Update development dependencies
14
+
3
15
  ## 13.2.1 / 2023-07-28
4
16
 
5
17
  * [BUGFIX] Fix deprecation on Rails Edge
data/LICENSE CHANGED
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -9,9 +9,7 @@ RouteTranslator is a gem to allow you to manage the translations of your app rou
9
9
 
10
10
  It started as a fork of the awesome [translate_routes](https://github.com/raul/translate_routes) plugin by [Raúl Murciano](https://github.com/raul).
11
11
 
12
- Right now it works with Rails 5.2, 6.x, and 7.x
13
-
14
-
12
+ Right now it works with Rails 6.1 and 7.x
15
13
 
16
14
  ## Quick Start
17
15
 
@@ -27,7 +25,7 @@ Right now it works with Rails 5.2, 6.x, and 7.x
27
25
  end
28
26
  ```
29
27
 
30
- The output of `rake routes.rb` would be:
28
+ The output of `bundle exec rails routes` would be:
31
29
 
32
30
  ```
33
31
  admin_cars GET /admin/cars(.:format) admin/cars#index
@@ -54,7 +52,13 @@ Right now it works with Rails 5.2, 6.x, and 7.x
54
52
 
55
53
  And execute `bundle install`
56
54
 
57
- 3. Wrap the groups of routes that you want to translate inside a `localized` block:
55
+ 3. Generate the default initializer:
56
+
57
+ ```sh
58
+ bundle exec rails g route_translator:install
59
+ ```
60
+
61
+ 4. Wrap the groups of routes that you want to translate inside a `localized` block:
58
62
 
59
63
  ```ruby
60
64
  Rails.application.routes.draw do
@@ -85,7 +89,7 @@ Right now it works with Rails 5.2, 6.x, and 7.x
85
89
  pricing: prix
86
90
  ```
87
91
 
88
- 4. Your routes are translated! Here's the output of your `rake routes` now:
92
+ 5. Your routes are translated! Here's the output of your `bundle exec rails routes` now:
89
93
 
90
94
  ```
91
95
  Prefix Verb URI Pattern Controller#Action
@@ -133,7 +137,7 @@ Right now it works with Rails 5.2, 6.x, and 7.x
133
137
 
134
138
  In :production environment, you should either set `config.i18n.fallbacks = false` or set up translations for your routes in every languages.
135
139
 
136
- 5. If you want to set `I18n.locale` from the url parameter locale, add
140
+ 6. If you want to set `I18n.locale` from the url parameter locale, add
137
141
  the following line in your `ApplicationController` or in the controllers
138
142
  that have translated content:
139
143
 
@@ -143,7 +147,6 @@ Right now it works with Rails 5.2, 6.x, and 7.x
143
147
 
144
148
  Note: you might be tempted to use `before_action` instead of `around_action`: just don't. That could lead to [thread-related issues](https://github.com/enriclluelles/route_translator/issues/44).
145
149
 
146
-
147
150
  ### Changing the Language
148
151
 
149
152
  To change the language and reload the appropriate route while staying on the same page, use the following code snippet:
@@ -158,7 +161,6 @@ If the page contains a localized slug, the above snippet does not work and a cus
158
161
 
159
162
  More information at [Generating translated URLs](https://github.com/enriclluelles/route_translator/wiki/Generating-translated-URLs)
160
163
 
161
-
162
164
  ### Namespaces
163
165
 
164
166
  You can translate a namespace route by either its `name` or `path` option:
@@ -198,7 +200,7 @@ You can translate a namespace route by either its `name` or `path` option:
198
200
  sold: vendues
199
201
  ```
200
202
 
201
- 4. Your namespaces are translated! Here's the output of your `rake routes` now:
203
+ 4. Your namespaces are translated! Here's the output of your `bundle exec rails routes` now:
202
204
 
203
205
  ```
204
206
  Prefix Verb URI Pattern Controller#Action
@@ -210,7 +212,6 @@ You can translate a namespace route by either its `name` or `path` option:
210
212
  sold_cars_cars_en GET /sold/cars(.:format) sold_cars/cars#index {:locale=>"en"}
211
213
  ```
212
214
 
213
-
214
215
  ### Inflections
215
216
 
216
217
  At the moment inflections are not supported, but you can use the following workaround:
@@ -253,8 +254,6 @@ edit_category_en GET /categories/:id/edit(.:format) categories#edit {:loca
253
254
  DELETE /categories/:id(.:format) categories#destroy {:locale=>"en"}
254
255
  ```
255
256
 
256
-
257
-
258
257
  ## Configuration
259
258
 
260
259
  You can configure RouteTranslator via an initializer or using the different environment config files.
@@ -266,27 +265,19 @@ RouteTranslator.config do |config|
266
265
  end
267
266
  ```
268
267
 
269
-
270
268
  ### Available Configurations
271
269
 
272
270
  | Option | Description | Default |
273
271
  | ------ | ----------- |-------- |
274
- | `available_locales` | Limits the locales for which URLs should be generated for. Accepts an array of strings or symbols. When empty, translations will be generated for all `I18n.available_locales` | `[]` |
275
- | `disable_fallback` | Creates 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` |
276
- | `force_locale` | Forces the locale to be added to all generated route paths, even for the default locale | `false` |
277
- | `generate_unlocalized_routes` | Adds translated routes without deleting original unlocalized versions. **Note:** Autosets `force_locale` to `true` | `false` |
278
- | `generate_unnamed_unlocalized_routes` | Adds 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` |
279
- | `hide_locale` | Forces the locale to be hidden on generated route paths | `false` |
280
- | `host_locales` | Sets `I18n.locale` based on `request.host`. Useful for apps accepting requests from more than one domain. See below for more details | `{}` |
272
+ | `available_locales` | Limit the locales for which URLs should be generated for. Accepts an array of strings or symbols. When empty, translations will be generated for all `I18n.available_locales` | `[]` |
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
+ | `force_locale` | Force the locale to be added to all generated route paths, even for the default locale | `false` |
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` |
277
+ | `hide_locale` | Force the locale to be hidden on generated route paths | `false` |
278
+ | `host_locales` | Set `I18n.locale` based on `request.host`. Useful for apps accepting requests from more than one domain. See below for more details | `{}` |
281
279
  | `locale_param_key` | The param key used to set the locale to the newly generated routes | `:locale` |
282
280
  | `locale_segment_proc` | The locale segment of the url will by default be `locale.to_s.downcase`. You can supply your own mechanism via a Proc that takes `locale` as an argument, e.g. `->(locale) { locale.to_s.upcase }` | `false` |
283
- | `i18n_use_slash_separator` | Use the exact controller path `account/foo` for looking up translations instead of nested keys `account.foo` | `false` |
284
-
285
- #### Deprecated options
286
-
287
- - `i18n_use_slash_separator` is deprecated and will be forced to `true` in the next major release of Route Translator. This only
288
- affects application with nested routes. Please set this option to `true` to remove the deprecation message and ensure
289
- to convert nested routes like `people.products` to the new `people/products`.
290
281
 
291
282
  ### Host-based Locale
292
283
 
@@ -330,7 +321,6 @@ This is to avoid odd behaviour brought about by route conflicts and because `hos
330
321
 
331
322
  NOTE: locale from parameters has priority over the one from hosts.
332
323
 
333
-
334
324
  ### Translations for similar routes with different namespaces
335
325
 
336
326
  If you have routes that (partially) share names in one locale, but must be translated differently in another locale, for example:
@@ -348,9 +338,8 @@ es:
348
338
  routes:
349
339
  favourites: favoritos
350
340
  controllers:
351
- people:
352
- products:
353
- favourites: fans
341
+ people/products:
342
+ favourites: fans
354
343
  ```
355
344
 
356
345
  Routes will be translated as in:
@@ -362,13 +351,18 @@ people_products_favourites_es GET /people/products/fans(.:format) people/
362
351
 
363
352
  It is also possible to translated resources scoped into a namespace. Example:
364
353
 
354
+ ```ruby
355
+ namespace :people do
356
+ resources :products, only: :index
357
+ end
358
+ ```
359
+
365
360
  ```yml
366
361
  es:
367
362
  routes:
368
363
  controllers:
369
- people:
370
- products:
371
- products: productos_favoritos
364
+ people/products:
365
+ products: productos_favoritos
372
366
  ```
373
367
 
374
368
  Routes will be translated as in:
@@ -379,7 +373,6 @@ people_products_es GET /people/productos_favoritos(.:format) people/produ
379
373
 
380
374
  The gem will lookup translations under `controllers` scope first and then lookup translations under `routes` scope.
381
375
 
382
-
383
376
  ### Change locale parameter position in the path
384
377
 
385
378
  If you need complex routing as `/:country/:locale/path/to/some/pages`, you can specify the position of your locale parameter in the following way:
@@ -392,8 +385,6 @@ scope ':country/:locale' do
392
385
  end
393
386
  ```
394
387
 
395
-
396
-
397
388
  ## Testing
398
389
  Testing your controllers with routes-translator is easy, just add a locale parameter as `String` for your localized routes. Otherwise, an `ActionController::UrlGenerationError` will raise.
399
390
 
@@ -408,8 +399,6 @@ describe 'GET index' do
408
399
  end
409
400
  ```
410
401
 
411
-
412
-
413
402
  ## Contributing
414
403
 
415
404
  Please read through our [contributing guidelines](CONTRIBUTING.md). Included are directions for opening issues, coding standards, and notes on development.
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteTranslator
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc 'Copy RouteTranslator default files'
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def copy_config
10
+ template 'config/initializers/route_translator.rb'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Use this setup block to configure all options available in RouteTranslator.
4
+ RouteTranslator.config do |config|
5
+ # Limit the locales for which URLs should be generated for. Accepts an array
6
+ # of strings or symbols. When empty, translations will be generated for all
7
+ # `I18n.available_locales`
8
+ # config.available_locales = []
9
+
10
+ # Create routes only for locales that have translations. For example, if
11
+ # we have `/examples` and a translation is not provided for `es`, the route
12
+ # helper of `examples_es` will not be created. Useful when one uses this with
13
+ # a locale route constraint, so non-es routes can return a `404` on a
14
+ # Spanish website
15
+ # config.disable_fallback = false
16
+
17
+ # Force the locale to be added to all generated route paths, even for the
18
+ # default locale
19
+ # config.force_locale = false
20
+
21
+ # Add translated routes without deleting original unlocalized versions.
22
+ # Note: Autosets `force_locale` to `true`
23
+ # config.generate_unlocalized_routes = false
24
+
25
+ # Add the behavior of `force_locale`, but with a named default route which
26
+ # behaves as if `generate_unlocalized_routes` was `true`. `root_path` will
27
+ # redirect to `/en` or `/es`, depending on the value of `I18n.locale`
28
+ # config.generate_unnamed_unlocalized_routes = false
29
+
30
+ # Force the locale to be hidden on generated route paths
31
+ # config.hide_locale = false
32
+
33
+ # Set `I18n.locale` based on `request.host`. Useful for apps accepting
34
+ # requests from more than one domain. See Readme for more details
35
+ # config.host_locales = {}
36
+
37
+ # The param key used to set the locale to the newly generated routes
38
+ # config.locale_param_key = :locale
39
+
40
+ # The locale segment of the url will by default be `locale.to_s.downcase`.
41
+ # You can supply your own mechanism via a Proc that takes `locale`
42
+ # as an argument, e.g. `->(locale) { locale.to_s.upcase }`
43
+ # config.locale_segment_proc = false
44
+ end
@@ -16,11 +16,7 @@ module RouteTranslator
16
16
  def scope
17
17
  @scope ||=
18
18
  if mapping.defaults[:controller]
19
- if RouteTranslator.config.i18n_use_slash_separator
20
- %i[routes controllers].push mapping.defaults[:controller]
21
- else
22
- %i[routes controllers].concat mapping.defaults[:controller].split('/').map(&:to_sym)
23
- end
19
+ %i[routes controllers].push mapping.defaults[:controller]
24
20
  else
25
21
  %i[routes controllers]
26
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RouteTranslator
4
- VERSION = '13.2.1'
4
+ VERSION = '14.0.1'
5
5
  end
@@ -21,8 +21,7 @@ module RouteTranslator
21
21
  hide_locale: false,
22
22
  host_locales: {},
23
23
  locale_param_key: :locale,
24
- locale_segment_proc: false,
25
- i18n_use_slash_separator: false
24
+ locale_segment_proc: false
26
25
  }.freeze
27
26
 
28
27
  Configuration = Struct.new(*DEFAULT_CONFIGURATION.keys)
@@ -37,17 +36,7 @@ module RouteTranslator
37
36
  @config.hide_locale = true
38
37
  end
39
38
 
40
- def check_deprecations
41
- return if @config.i18n_use_slash_separator
42
-
43
- deprecator.warn <<~MSG
44
- `i18n_use_slash_separator` set to `false` is deprecated and will be
45
- removed in the next major release of Route Translator to match
46
- Rails' ActiveRecord nested model syntax.
47
-
48
- More information at https://github.com/enriclluelles/route_translator/pull/285
49
- MSG
50
- end
39
+ def check_deprecations; end
51
40
  end
52
41
 
53
42
  module_function
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: 13.2.1
4
+ version: 14.0.1
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: 2023-07-28 00:00:00.000000000 Z
13
+ date: 2023-09-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.2'
21
+ version: '6.1'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '7.1'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '5.2'
31
+ version: '6.1'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '7.1'
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '5.2'
41
+ version: '6.1'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
44
  version: '7.1'
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '5.2'
51
+ version: '6.1'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '7.1'
@@ -64,6 +64,8 @@ files:
64
64
  - CHANGELOG.md
65
65
  - LICENSE
66
66
  - README.md
67
+ - lib/generators/route_translator/install_generator.rb
68
+ - lib/generators/route_translator/templates/config/initializers/route_translator.rb
67
69
  - lib/route_translator.rb
68
70
  - lib/route_translator/extensions.rb
69
71
  - lib/route_translator/extensions/action_controller.rb
@@ -93,14 +95,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
95
  requirements:
94
96
  - - ">="
95
97
  - !ruby/object:Gem::Version
96
- version: '2.6'
98
+ version: '2.7'
97
99
  required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  requirements:
99
101
  - - ">="
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  requirements: []
103
- rubygems_version: 3.4.1
105
+ rubygems_version: 3.4.19
104
106
  signing_key:
105
107
  specification_version: 4
106
108
  summary: Translate your Rails routes in a simple manner