route_translator 7.1.0 → 8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccd0d757f83bdef655cbbd42b82a1e4c819298a2e6fde735f8082b197fcc9e5a
4
- data.tar.gz: 438c1495fa784da92180d44616e0c568d302cf67cc487c1867ad9a01759ff87f
3
+ metadata.gz: 1a22c81c0b6e1cba0291cc7a2ff1f576d5d00a418c920633e1aa8ef715a7c09c
4
+ data.tar.gz: b6d1d0ccf414ef08abb513136d25d4004915e05dec690992b1ccb6f3f814b2a1
5
5
  SHA512:
6
- metadata.gz: a722c1b6ee1a5c51ba8d5bf038304a54d727c2126e2e3386261577fb554d8886aea76e66704dbe9eb84d17a493261df3389991ffd011ee30023392374f3be2c7
7
- data.tar.gz: ba31fe5c99c9c6999def680b75814357355a7538735048019d2ca982c699cb3bb67234675cfd56ea536d6584bfb46c223b1402fc7610690ea7d882b33831a524
6
+ metadata.gz: 954551495bcde48e69af19e26b0d9062fcaabf4677fc171bb23e7adf87cfd2549a7be64bc495b382c650e1fb1068be7ce889460f54464c9fa4ef3eaf97c0bf9a
7
+ data.tar.gz: df05ec4b6ee86528b7d39d49277ba9cb9c7dddf731329ab0ad5ad92c84571951d9b15a188a10bb9a058340955dc75e5379b88920ee132cc3c3409d616b24aa5b
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.2.0 / 2020-11-03
4
+
5
+ * [FEATURE] Add Rails 6.1 compatibility
6
+ * [ENHANCEMENT] Update development dependencies
7
+
8
+ ## 8.1.0 / 2020-08-10
9
+
10
+ * [FEATURE] Allow Ruby 3.0.0
11
+ * [ENHANCEMENT] Test against latest Ruby versions
12
+ * [ENHANCEMENT] Update development dependencies
13
+
14
+ ## 8.0.0 / 2020-04-17
15
+
16
+ * [FEATURE] Drop Ruby 2.3 support
17
+ * [ENHANCEMENT] Add gem metadata for RubyGems.org
18
+ * [ENHANCEMENT] Test against latest Ruby versions
19
+ * [ENHANCEMENT] Update development dependencies
20
+
21
+ ## 7.1.2 / 2020-03-02
22
+
23
+ * [BUGFIX] Fix lazy load of action controller ([#206](https://github.com/enriclluelles/route_translator/pull/206))
24
+ * [ENHANCEMENT] Update development dependencies
25
+
26
+ ## 7.1.1 / 2019-12-26
27
+
28
+ * [ENHANCEMENT] Minor improvements to configuration and tests
29
+
3
30
  ## 7.1.0 / 2019-12-26
4
31
 
5
32
  * [ENHANCEMENT] Use Addressable gem for URI parsing
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es], 2019 Geremia Taglialatela
3
+ Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es], 2020 Geremia Taglialatela
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # RouteTranslator
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/route_translator.svg)](https://badge.fury.io/rb/route_translator)
4
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=route_translator&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=route_translator&package-manager=bundler&version-scheme=semver)
4
5
  [![Build Status](https://travis-ci.org/enriclluelles/route_translator.svg?branch=master)](https://travis-ci.org/enriclluelles/route_translator)
5
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/1c369ce6147724b353fc/maintainability)](https://codeclimate.com/github/enriclluelles/route_translator/maintainability)
6
7
  [![Coverage Status](https://coveralls.io/repos/github/enriclluelles/route_translator/badge.svg?branch=master)](https://coveralls.io/github/enriclluelles/route_translator?branch=master)
@@ -9,7 +10,7 @@ RouteTranslator is a gem to allow you to manage the translations of your app rou
9
10
 
10
11
  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
12
 
12
- Right now it works with Rails 5.x and Rails 6.0
13
+ Right now it works with Rails 5.x and Rails 6.x
13
14
 
14
15
 
15
16
 
@@ -144,6 +145,21 @@ Right now it works with Rails 5.x and Rails 6.0
144
145
  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
146
 
146
147
 
148
+ ### Changing the Language
149
+
150
+ To change the language and reload the appropriate route while staying on the same page, use the following code snippet:
151
+
152
+ ```ruby
153
+ link_to url_for(locale: 'es'), hreflang: 'es', rel: 'alternate'
154
+ ```
155
+
156
+ Although locales are stored by Rails as a symbol (`:es`), when linking to a page in a different locale you need to use a string (`'es'`). Otherwise, instead of a namespaced route (`/es/my-route`) you will get a parameterized route (`/my-route?locale=es`).
157
+
158
+ If the page contains a localized slug, the above snippet does not work and a custom implementation is neede.
159
+
160
+ More information at [Generating translated URLs](https://github.com/enriclluelles/route_translator/wiki/Generating-translated-URLs)
161
+
162
+
147
163
  ### Namespaces
148
164
 
149
165
  You can translate a namespace route by either its `name` or `path` option:
@@ -358,11 +374,12 @@ end
358
374
 
359
375
 
360
376
  ## Testing
361
- Testing your controllers with routes-translator is easy, just add a locale parameter for your localized routes. Otherwise, an ActionController::UrlGenerationError will raise.
377
+ 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.
362
378
 
363
379
  ```ruby
364
380
  describe 'GET index' do
365
381
  it 'should respond with success' do
382
+ # Remember to pass the locale param as String
366
383
  get :index, locale: 'fr'
367
384
 
368
385
  expect(response).to be_success
@@ -42,20 +42,26 @@ module RouteTranslator
42
42
 
43
43
  module_function
44
44
 
45
- def config(&block)
45
+ def config
46
46
  @config ||= Configuration.new
47
47
 
48
48
  DEFAULT_CONFIGURATION.each do |option, value|
49
49
  @config[option] ||= value
50
50
  end
51
51
 
52
- yield @config if block
52
+ yield @config if block_given?
53
53
 
54
- resolve_host_locale_config_conflicts unless @config.host_locales.empty?
54
+ resolve_host_locale_config_conflicts if @config.host_locales.present?
55
55
 
56
56
  @config
57
57
  end
58
58
 
59
+ def reset_config
60
+ @config = nil
61
+
62
+ config
63
+ end
64
+
59
65
  def available_locales
60
66
  locales = config.available_locales
61
67
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_controller'
4
3
  require 'active_support/concern'
5
4
 
6
5
  module RouteTranslator
@@ -21,22 +20,12 @@ module RouteTranslator
21
20
  I18n.locale = old_locale if locale_from_url
22
21
  end
23
22
  end
24
-
25
- module TestCase
26
- extend ActiveSupport::Concern
27
- include ActionController::UrlFor
28
-
29
- included do
30
- delegate :env, :request, to: :@controller
31
- end
32
-
33
- def _routes
34
- @routes
35
- end
36
- end
37
23
  end
38
24
 
39
25
  ActiveSupport.on_load(:action_controller) do
40
- ActionController::Base.include RouteTranslator::Controller
41
- ActionController::TestCase.include RouteTranslator::TestCase if ENV['RAILS_ENV'] == 'test'
26
+ include RouteTranslator::Controller
27
+ if ENV['RAILS_ENV'] == 'test'
28
+ require 'route_translator/extensions/test_case'
29
+ ActionController::TestCase.include RouteTranslator::TestCase
30
+ end
42
31
  end
@@ -11,7 +11,7 @@ module ActionDispatch
11
11
  @localized = false
12
12
  end
13
13
 
14
- # rubocop:disable Lint/UnderscorePrefixedVariableName
14
+ # rubocop:disable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
15
15
  def add_route(action, controller, options, _path, to, via, formatted, anchor, options_constraints) # :nodoc:
16
16
  return super unless @localized
17
17
 
@@ -22,7 +22,7 @@ module ActionDispatch
22
22
 
23
23
  default_action = options.delete(:action) || @scope[:action]
24
24
 
25
- if action =~ %r{^[\w\-\/]+$}
25
+ if %r{^[\w\-\/]+$}.match?(action)
26
26
  default_action ||= action.tr('-', '_') unless action.include?('/')
27
27
  else
28
28
  action = nil
@@ -40,7 +40,7 @@ module ActionDispatch
40
40
  mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
41
41
  @set.add_localized_route(mapping, ast, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options)
42
42
  end
43
- # rubocop:enable Lint/UnderscorePrefixedVariableName
43
+ # rubocop:enable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
44
44
 
45
45
  private
46
46
 
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_controller'
4
+
5
+ module RouteTranslator
6
+ module TestCase
7
+ extend ActiveSupport::Concern
8
+ include ActionController::UrlFor
9
+
10
+ included do
11
+ delegate :env, :request, to: :@controller
12
+ end
13
+
14
+ def _routes
15
+ @routes
16
+ end
17
+ end
18
+ end
@@ -12,7 +12,7 @@ module RouteTranslator
12
12
  end
13
13
 
14
14
  def native_locale?(locale)
15
- locale.to_s.match(/native_/).present?
15
+ locale.to_s.include?('native_')
16
16
  end
17
17
 
18
18
  def native_locales
@@ -23,7 +23,7 @@ module RouteTranslator
23
23
 
24
24
  def locale_from_host(host)
25
25
  locales = RouteTranslator.config.host_locales.each_with_object([]) do |(pattern, locale), result|
26
- result << locale.to_sym if host =~ regex_for(pattern)
26
+ result << locale.to_sym if host&.match?(regex_for(pattern))
27
27
  end
28
28
  locales &= I18n.available_locales
29
29
  locales.first&.to_sym
@@ -24,10 +24,10 @@ module RouteTranslator
24
24
  handler = proc { |exception| exception }
25
25
  opts = { locale: locale, scope: scope }
26
26
 
27
- if I18n.translate(str, **opts.merge(exception_handler: handler)).is_a?(I18n::MissingTranslation)
28
- I18n.translate str, **opts.merge(fallback_options(str, locale))
27
+ if I18n.t(str, **opts.merge(exception_handler: handler)).is_a?(I18n::MissingTranslation)
28
+ I18n.t str, **opts.merge(fallback_options(str, locale))
29
29
  else
30
- I18n.translate str, **opts
30
+ I18n.t str, **opts
31
31
  end
32
32
  end
33
33
 
@@ -51,12 +51,12 @@ module RouteTranslator
51
51
  def translate(segment, locale, scope)
52
52
  return segment if segment.empty?
53
53
 
54
- if segment.starts_with?(':')
54
+ if segment.start_with?(':')
55
55
  named_param, hyphenized = segment.split('-', 2)
56
56
  return "#{named_param}-#{translate(hyphenized, locale, scope)}" if hyphenized
57
57
  end
58
58
 
59
- return segment if segment.starts_with?('(', '*') || segment.include?(':')
59
+ return segment if segment.start_with?('(', '*') || segment.include?(':')
60
60
 
61
61
  appended_part = segment.slice!(/(\()$/)
62
62
  str = translatable_segment(segment)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RouteTranslator
4
- VERSION = '7.1.0'
4
+ VERSION = '8.2.0'
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geremia Taglialatela
8
8
  - Enric Lluelles
9
9
  - Raul Murciano
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-12-26 00:00:00.000000000 Z
13
+ date: 2020-11-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 5.0.0.1
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '6.1'
24
+ version: '6.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 5.0.0.1
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.1'
34
+ version: '6.2'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activesupport
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -41,7 +41,7 @@ dependencies:
41
41
  version: 5.0.0.1
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '6.1'
44
+ version: '6.2'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,7 +51,7 @@ dependencies:
51
51
  version: 5.0.0.1
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '6.1'
54
+ version: '6.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: addressable
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.2'
75
+ version: '2.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.2'
82
+ version: '2.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: byebug
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -106,28 +106,28 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 0.14.0
109
+ version: 0.18.0
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: 0.14.0
116
+ version: 0.18.0
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: minitest
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '5.13'
123
+ version: '5.14'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '5.13'
130
+ version: '5.14'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rails
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  version: 5.0.0.1
138
138
  - - "<"
139
139
  - !ruby/object:Gem::Version
140
- version: '6.1'
140
+ version: '6.2'
141
141
  type: :development
142
142
  prerelease: false
143
143
  version_requirements: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ dependencies:
147
147
  version: 5.0.0.1
148
148
  - - "<"
149
149
  - !ruby/object:Gem::Version
150
- version: '6.1'
150
+ version: '6.2'
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: rake
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -168,56 +168,62 @@ dependencies:
168
168
  requirements:
169
169
  - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 0.78.0
171
+ version: 1.1.0
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
176
  - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 0.78.0
178
+ version: 1.1.0
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: rubocop-performance
181
181
  requirement: !ruby/object:Gem::Requirement
182
182
  requirements:
183
183
  - - "~>"
184
184
  - !ruby/object:Gem::Version
185
- version: '1.5'
185
+ version: '1.8'
186
186
  type: :development
187
187
  prerelease: false
188
188
  version_requirements: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
- version: '1.5'
192
+ version: '1.8'
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: rubocop-rails
195
195
  requirement: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: '2.4'
199
+ version: '2.8'
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
- version: '2.4'
206
+ version: '2.8'
207
207
  - !ruby/object:Gem::Dependency
208
208
  name: simplecov
209
209
  requirement: !ruby/object:Gem::Requirement
210
210
  requirements:
211
- - - "~>"
211
+ - - ">="
212
212
  - !ruby/object:Gem::Version
213
- version: 0.17.1
213
+ version: 0.18.5
214
+ - - "<"
215
+ - !ruby/object:Gem::Version
216
+ version: '0.20'
214
217
  type: :development
215
218
  prerelease: false
216
219
  version_requirements: !ruby/object:Gem::Requirement
217
220
  requirements:
218
- - - "~>"
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: 0.18.5
224
+ - - "<"
219
225
  - !ruby/object:Gem::Version
220
- version: 0.17.1
226
+ version: '0.20'
221
227
  description: Translates the Rails routes of your application into the languages defined
222
228
  in your locale files
223
229
  email:
@@ -235,6 +241,7 @@ files:
235
241
  - lib/route_translator/extensions/action_controller.rb
236
242
  - lib/route_translator/extensions/mapper.rb
237
243
  - lib/route_translator/extensions/route_set.rb
244
+ - lib/route_translator/extensions/test_case.rb
238
245
  - lib/route_translator/host.rb
239
246
  - lib/route_translator/host_path_consistency_lambdas.rb
240
247
  - lib/route_translator/locale_sanitizer.rb
@@ -247,24 +254,27 @@ files:
247
254
  homepage: https://github.com/enriclluelles/route_translator
248
255
  licenses:
249
256
  - MIT
250
- metadata: {}
251
- post_install_message:
257
+ metadata:
258
+ bug_tracker_uri: https://github.com/enriclluelles/route_translator/issues
259
+ changelog_uri: https://github.com/enriclluelles/route_translator/blob/master/CHANGELOG.md
260
+ source_code_uri: https://github.com/enriclluelles/route_translator
261
+ post_install_message:
252
262
  rdoc_options: []
253
263
  require_paths:
254
264
  - lib
255
265
  required_ruby_version: !ruby/object:Gem::Requirement
256
266
  requirements:
257
- - - "~>"
267
+ - - ">="
258
268
  - !ruby/object:Gem::Version
259
- version: '2.3'
269
+ version: '2.4'
260
270
  required_rubygems_version: !ruby/object:Gem::Requirement
261
271
  requirements:
262
272
  - - ">="
263
273
  - !ruby/object:Gem::Version
264
274
  version: '0'
265
275
  requirements: []
266
- rubygems_version: 3.1.2
267
- signing_key:
276
+ rubygems_version: 3.1.4
277
+ signing_key:
268
278
  specification_version: 4
269
279
  summary: Translate your Rails routes in a simple manner
270
280
  test_files: []