route_translator 13.2.1 → 14.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +27 -24
- data/lib/generators/route_translator/install_generator.rb +14 -0
- data/lib/generators/route_translator/templates/config/initializers/route_translator.rb +44 -0
- data/lib/route_translator/railtie.rb +9 -0
- data/lib/route_translator/route.rb +1 -5
- data/lib/route_translator/version.rb +1 -1
- data/lib/route_translator.rb +4 -13
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92c7961768c35baf18cf30e3316b8224ecad45a76e7b0c262f39e9f8945787e9
|
4
|
+
data.tar.gz: 156b961c7893072a233cc8954e7fac1e640bec44ac76681de4611be48191b5ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc77e8f966037a9d7a1b38b04215ca9ba2b0c6ca7d5bd2e2c1252d390c2ba60c4b8cf58f221ed7915a82eee131fe22500d20149f51bfefc78cfa8292d3bacf0
|
7
|
+
data.tar.gz: 1f35cb097d1c2eed38b8b1650d5d05c0b9f8d42e5281d2b5a6dd963786224107337c34651fc0f62176bfb766e961a8acc96646d55fa9b90d9d1b71e84adc43c6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 14.0.0 / 2023-09-02
|
4
|
+
|
5
|
+
* [FEATURE] BREAKING CHANGE: Force standard nested separator (Upgrade guide at [#285](https://github.com/enriclluelles/route_translator/pull/285))
|
6
|
+
* [FEATURE] Drop Ruby 2.6 compatibility
|
7
|
+
* [FEATURE] Drop Rails < 6.1 compatibility
|
8
|
+
* [FEATURE] Add initializer generator
|
9
|
+
* [ENHANCEMENT] Update development dependencies
|
10
|
+
|
3
11
|
## 13.2.1 / 2023-07-28
|
4
12
|
|
5
13
|
* [BUGFIX] Fix deprecation on Rails Edge
|
data/README.md
CHANGED
@@ -9,7 +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
|
12
|
+
Right now it works with Rails 6.1 and 7.x
|
13
13
|
|
14
14
|
|
15
15
|
|
@@ -54,7 +54,13 @@ Right now it works with Rails 5.2, 6.x, and 7.x
|
|
54
54
|
|
55
55
|
And execute `bundle install`
|
56
56
|
|
57
|
-
3.
|
57
|
+
3. Generate the default initializer:
|
58
|
+
|
59
|
+
```sh
|
60
|
+
bundle exec rails g route_translator:install
|
61
|
+
```
|
62
|
+
|
63
|
+
4. Wrap the groups of routes that you want to translate inside a `localized` block:
|
58
64
|
|
59
65
|
```ruby
|
60
66
|
Rails.application.routes.draw do
|
@@ -85,7 +91,7 @@ Right now it works with Rails 5.2, 6.x, and 7.x
|
|
85
91
|
pricing: prix
|
86
92
|
```
|
87
93
|
|
88
|
-
|
94
|
+
5. Your routes are translated! Here's the output of your `rake routes` now:
|
89
95
|
|
90
96
|
```
|
91
97
|
Prefix Verb URI Pattern Controller#Action
|
@@ -133,7 +139,7 @@ Right now it works with Rails 5.2, 6.x, and 7.x
|
|
133
139
|
|
134
140
|
In :production environment, you should either set `config.i18n.fallbacks = false` or set up translations for your routes in every languages.
|
135
141
|
|
136
|
-
|
142
|
+
6. If you want to set `I18n.locale` from the url parameter locale, add
|
137
143
|
the following line in your `ApplicationController` or in the controllers
|
138
144
|
that have translated content:
|
139
145
|
|
@@ -271,22 +277,15 @@ end
|
|
271
277
|
|
272
278
|
| Option | Description | Default |
|
273
279
|
| ------ | ----------- |-------- |
|
274
|
-
| `available_locales` |
|
275
|
-
| `disable_fallback` |
|
276
|
-
| `force_locale` |
|
277
|
-
| `generate_unlocalized_routes` |
|
278
|
-
| `generate_unnamed_unlocalized_routes` |
|
279
|
-
| `hide_locale` |
|
280
|
-
| `host_locales` |
|
280
|
+
| `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` | `[]` |
|
281
|
+
| `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` |
|
282
|
+
| `force_locale` | Force the locale to be added to all generated route paths, even for the default locale | `false` |
|
283
|
+
| `generate_unlocalized_routes` | Add translated routes without deleting original unlocalized versions. **Note:** Autosets `force_locale` to `true` | `false` |
|
284
|
+
| `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` |
|
285
|
+
| `hide_locale` | Force the locale to be hidden on generated route paths | `false` |
|
286
|
+
| `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
287
|
| `locale_param_key` | The param key used to set the locale to the newly generated routes | `:locale` |
|
282
288
|
| `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
289
|
|
291
290
|
### Host-based Locale
|
292
291
|
|
@@ -348,9 +347,8 @@ es:
|
|
348
347
|
routes:
|
349
348
|
favourites: favoritos
|
350
349
|
controllers:
|
351
|
-
people:
|
352
|
-
|
353
|
-
favourites: fans
|
350
|
+
people/products:
|
351
|
+
favourites: fans
|
354
352
|
```
|
355
353
|
|
356
354
|
Routes will be translated as in:
|
@@ -362,13 +360,18 @@ people_products_favourites_es GET /people/products/fans(.:format) people/
|
|
362
360
|
|
363
361
|
It is also possible to translated resources scoped into a namespace. Example:
|
364
362
|
|
363
|
+
```ruby
|
364
|
+
namespace :people do
|
365
|
+
resources :products, only: :index
|
366
|
+
end
|
367
|
+
```
|
368
|
+
|
365
369
|
```yml
|
366
370
|
es:
|
367
371
|
routes:
|
368
372
|
controllers:
|
369
|
-
people:
|
370
|
-
products:
|
371
|
-
products: productos_favoritos
|
373
|
+
people/products:
|
374
|
+
products: productos_favoritos
|
372
375
|
```
|
373
376
|
|
374
377
|
Routes will be translated as in:
|
@@ -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
|
-
|
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
|
data/lib/route_translator.rb
CHANGED
@@ -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
|
@@ -96,3 +85,5 @@ module RouteTranslator
|
|
96
85
|
@deprecator ||= ActiveSupport::Deprecation.new(RouteTranslator::VERSION, 'RouteTranslator')
|
97
86
|
end
|
98
87
|
end
|
88
|
+
|
89
|
+
require 'route_translator/railtie' if defined?(Rails)
|
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
|
+
version: 14.0.0
|
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-
|
13
|
+
date: 2023-09-02 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: '
|
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: '
|
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: '
|
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: '
|
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
|
@@ -71,6 +73,7 @@ files:
|
|
71
73
|
- lib/route_translator/extensions/route_set.rb
|
72
74
|
- lib/route_translator/extensions/test_case.rb
|
73
75
|
- lib/route_translator/host.rb
|
76
|
+
- lib/route_translator/railtie.rb
|
74
77
|
- lib/route_translator/route.rb
|
75
78
|
- lib/route_translator/translator.rb
|
76
79
|
- lib/route_translator/translator/path.rb
|
@@ -93,14 +96,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
96
|
requirements:
|
94
97
|
- - ">="
|
95
98
|
- !ruby/object:Gem::Version
|
96
|
-
version: '2.
|
99
|
+
version: '2.7'
|
97
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
101
|
requirements:
|
99
102
|
- - ">="
|
100
103
|
- !ruby/object:Gem::Version
|
101
104
|
version: '0'
|
102
105
|
requirements: []
|
103
|
-
rubygems_version: 3.4.
|
106
|
+
rubygems_version: 3.4.19
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Translate your Rails routes in a simple manner
|