route_translator 7.1.1 → 8.2.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: 570472c4c19fb73c69f7d010b705b8fbd3a1c426944b87b528e9436342e18faf
4
- data.tar.gz: 7367796df62fabe93cabd32b5ee6966180776f811b24185277ef1e92266ddf9e
3
+ metadata.gz: 2dee48b403034cdfafb803907c15c3f68ecefd282ae3d58eef7b813259088443
4
+ data.tar.gz: 374a81216e935e29a9cdedc3441bd12bf3480025e169e72f6124a30ebe4dc59b
5
5
  SHA512:
6
- metadata.gz: b95c8a800676cb8e9c52982fe762b89aa1b236fee84eae8eae70acc35fe176f6307d1c295ef4b47216851be10aded8476775f2d52f43da854ee418601da56abf
7
- data.tar.gz: f561ec0d27cc21881faa818c0dfb093bf01017684ea58850607a7978476fd443b8c5b356f86665e20265474b41daaedc54b7d449a5d00440bf520fd4b1580415
6
+ metadata.gz: 1d9215d8faeeda69a1ce08c3847e00e640b74a586d1e5d81aac27b191d8230273a35c4b8d9283767ec2a0d15c6f43ba987f49a5e15a18574c8a55fa5bfd661cb
7
+ data.tar.gz: a13a8a4646af8176ce64ef728c41b44559e6f1d12f87ed5a1fd8750ea5ad28fc30d4fcfdbb35bc2d563b06b6e527519612789a0b2d9106bf113f98edadb69355
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.2.1 / 2020-11-03
4
+
5
+ * [ENHANCEMENT] Fix deprecation with URI.parser ([#234](https://github.com/enriclluelles/route_translator/pull/234))
6
+
7
+ ## 8.2.0 / 2020-11-03
8
+
9
+ * [FEATURE] Add Rails 6.1 compatibility
10
+ * [ENHANCEMENT] Update development dependencies
11
+
12
+ ## 8.1.0 / 2020-08-10
13
+
14
+ * [FEATURE] Allow Ruby 3.0.0
15
+ * [ENHANCEMENT] Test against latest Ruby versions
16
+ * [ENHANCEMENT] Update development dependencies
17
+
18
+ ## 8.0.0 / 2020-04-17
19
+
20
+ * [FEATURE] Drop Ruby 2.3 support
21
+ * [ENHANCEMENT] Add gem metadata for RubyGems.org
22
+ * [ENHANCEMENT] Test against latest Ruby versions
23
+ * [ENHANCEMENT] Update development dependencies
24
+
25
+ ## 7.1.2 / 2020-03-02
26
+
27
+ * [BUGFIX] Fix lazy load of action controller ([#206](https://github.com/enriclluelles/route_translator/pull/206))
28
+ * [ENHANCEMENT] Update development dependencies
29
+
3
30
  ## 7.1.1 / 2019-12-26
4
31
 
5
32
  * [ENHANCEMENT] Minor improvements to configuration and tests
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
@@ -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
@@ -34,13 +34,13 @@ module ActionDispatch
34
34
  name_for_action(options.delete(:as), action)
35
35
  end
36
36
 
37
- path = Mapping.normalize_path URI.parser.escape(path), formatted
37
+ path = Mapping.normalize_path URI::DEFAULT_PARSER.escape(path), formatted
38
38
  ast = Journey::Parser.parse path
39
39
 
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.1'
4
+ VERSION = '8.2.1'
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.1
4
+ version: 8.2.1
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: []