route_translator 7.0.1 → 8.1.0

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: b2f33ffee939f6a410cc991d1e6937123d096263461dee1ff8c1f2d9d0ab4286
4
- data.tar.gz: f23abb52df341f50327dcca5e357b1d48fdebf1520218c3f152998c9eeedede0
3
+ metadata.gz: 580ad3a9bbfc1e8dffbc91065e78742331817785df3588381a26366164077f74
4
+ data.tar.gz: 5c4b9f4303af246b42db421d85e59b7a9100ca680b88d857a1551da2f148bb62
5
5
  SHA512:
6
- metadata.gz: 529f1d1621286b84c0e47a532a6f17ff4efd901153b2086f13ebf3f4c18462d65470f91ac78d9180601f8af38ed754eecab3869c56b8f2bd39ba90b9341cc83b
7
- data.tar.gz: 145661421d0bc78601484d1e0c41fb525306814fa97057e2eeb41fce0a24f7399a42dd4e8361a8e58001468eb0a257472227bd461a9283bdb3510082d9594c07
6
+ metadata.gz: 20c6af6178eb2a280e41eb7ad7581e2fd70c89b46b119f7de6f27e7627f06b7a67facd8fe068f349b6b4f695a752f3885deef418c984c75b25923c336767411f
7
+ data.tar.gz: 0a44a9bec9161a5b00880ec1d669f2bbf87b9c2e78f4e40cd8e70014b24dd4d17d04d28c987fa478ddaf150c287548c1ab5061619b6d2077ea473bab7707abad
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.1.0 / 2020-08-10
4
+
5
+ * [FEATURE] Allow Ruby 3.0.0
6
+ * [ENHANCEMENT] Test against latest Ruby versions
7
+ * [ENHANCEMENT] Update development dependencies
8
+
9
+ ## 8.0.0 / 2020-04-17
10
+
11
+ * [FEATURE] Drop Ruby 2.3 support
12
+ * [ENHANCEMENT] Add gem metadata for RubyGems.org
13
+ * [ENHANCEMENT] Test against latest Ruby versions
14
+ * [ENHANCEMENT] Update development dependencies
15
+
16
+ ## 7.1.2 / 2020-03-02
17
+
18
+ * [BUGFIX] Fix lazy load of action controller ([#206](https://github.com/enriclluelles/route_translator/pull/206))
19
+ * [ENHANCEMENT] Update development dependencies
20
+
21
+ ## 7.1.1 / 2019-12-26
22
+
23
+ * [ENHANCEMENT] Minor improvements to configuration and tests
24
+
25
+ ## 7.1.0 / 2019-12-26
26
+
27
+ * [ENHANCEMENT] Use Addressable gem for URI parsing
28
+ * [ENHANCEMENT] Fix Ruby 2.7 deprecations
29
+ * [ENHANCEMENT] Update dependencies
30
+
3
31
  ## 7.0.1 / 2019-10-14
4
32
 
5
33
  * [BUGFIX] Fix missing dup on blocks ([#203](https://github.com/enriclluelles/route_translator/pull/203))
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)
@@ -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,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support'
4
+ require 'addressable/uri'
4
5
 
5
6
  require 'route_translator/extensions'
6
7
  require 'route_translator/translator'
@@ -41,20 +42,26 @@ module RouteTranslator
41
42
 
42
43
  module_function
43
44
 
44
- def config(&block)
45
+ def config
45
46
  @config ||= Configuration.new
46
47
 
47
48
  DEFAULT_CONFIGURATION.each do |option, value|
48
49
  @config[option] ||= value
49
50
  end
50
51
 
51
- yield @config if block
52
+ yield @config if block_given?
52
53
 
53
- resolve_host_locale_config_conflicts unless @config.host_locales.empty?
54
+ resolve_host_locale_config_conflicts if @config.host_locales.present?
54
55
 
55
56
  @config
56
57
  end
57
58
 
59
+ def reset_config
60
+ @config = nil
61
+
62
+ config
63
+ end
64
+
58
65
  def available_locales
59
66
  locales = config.available_locales
60
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
 
@@ -35,7 +35,7 @@ module RouteTranslator
35
35
  sanitized_locale = RouteTranslator::LocaleSanitizer.sanitize(locale)
36
36
  translated_resource = translate_resource(str, sanitized_locale, scope)
37
37
 
38
- URI.escape translated_resource
38
+ Addressable::URI.normalize_component translated_resource
39
39
  end
40
40
  end
41
41
 
@@ -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.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.0.1'
4
+ VERSION = '8.1.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.0.1
4
+ version: 8.1.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-10-14 00:00:00.000000000 Z
13
+ date: 2020-10-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '6.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: addressable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: appraisal
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '2.2'
75
+ version: '2.3'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '2.2'
82
+ version: '2.3'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: byebug
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -92,28 +106,28 @@ dependencies:
92
106
  requirements:
93
107
  - - "~>"
94
108
  - !ruby/object:Gem::Version
95
- version: 0.13.3
109
+ version: 0.18.0
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: 0.13.3
116
+ version: 0.18.0
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: minitest
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '5.12'
123
+ version: '5.14'
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: '5.12'
130
+ version: '5.14'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: rails
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -154,56 +168,62 @@ dependencies:
154
168
  requirements:
155
169
  - - "~>"
156
170
  - !ruby/object:Gem::Version
157
- version: 0.75.1
171
+ version: 0.93.0
158
172
  type: :development
159
173
  prerelease: false
160
174
  version_requirements: !ruby/object:Gem::Requirement
161
175
  requirements:
162
176
  - - "~>"
163
177
  - !ruby/object:Gem::Version
164
- version: 0.75.1
178
+ version: 0.93.0
165
179
  - !ruby/object:Gem::Dependency
166
180
  name: rubocop-performance
167
181
  requirement: !ruby/object:Gem::Requirement
168
182
  requirements:
169
183
  - - "~>"
170
184
  - !ruby/object:Gem::Version
171
- version: '1.5'
185
+ version: '1.8'
172
186
  type: :development
173
187
  prerelease: false
174
188
  version_requirements: !ruby/object:Gem::Requirement
175
189
  requirements:
176
190
  - - "~>"
177
191
  - !ruby/object:Gem::Version
178
- version: '1.5'
192
+ version: '1.8'
179
193
  - !ruby/object:Gem::Dependency
180
194
  name: rubocop-rails
181
195
  requirement: !ruby/object:Gem::Requirement
182
196
  requirements:
183
197
  - - "~>"
184
198
  - !ruby/object:Gem::Version
185
- version: '2.3'
199
+ version: '2.8'
186
200
  type: :development
187
201
  prerelease: false
188
202
  version_requirements: !ruby/object:Gem::Requirement
189
203
  requirements:
190
204
  - - "~>"
191
205
  - !ruby/object:Gem::Version
192
- version: '2.3'
206
+ version: '2.8'
193
207
  - !ruby/object:Gem::Dependency
194
208
  name: simplecov
195
209
  requirement: !ruby/object:Gem::Requirement
196
210
  requirements:
197
- - - "~>"
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 0.18.5
214
+ - - "<"
198
215
  - !ruby/object:Gem::Version
199
- version: 0.17.1
216
+ version: '0.20'
200
217
  type: :development
201
218
  prerelease: false
202
219
  version_requirements: !ruby/object:Gem::Requirement
203
220
  requirements:
204
- - - "~>"
221
+ - - ">="
205
222
  - !ruby/object:Gem::Version
206
- version: 0.17.1
223
+ version: 0.18.5
224
+ - - "<"
225
+ - !ruby/object:Gem::Version
226
+ version: '0.20'
207
227
  description: Translates the Rails routes of your application into the languages defined
208
228
  in your locale files
209
229
  email:
@@ -221,6 +241,7 @@ files:
221
241
  - lib/route_translator/extensions/action_controller.rb
222
242
  - lib/route_translator/extensions/mapper.rb
223
243
  - lib/route_translator/extensions/route_set.rb
244
+ - lib/route_translator/extensions/test_case.rb
224
245
  - lib/route_translator/host.rb
225
246
  - lib/route_translator/host_path_consistency_lambdas.rb
226
247
  - lib/route_translator/locale_sanitizer.rb
@@ -233,24 +254,27 @@ files:
233
254
  homepage: https://github.com/enriclluelles/route_translator
234
255
  licenses:
235
256
  - MIT
236
- metadata: {}
237
- 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:
238
262
  rdoc_options: []
239
263
  require_paths:
240
264
  - lib
241
265
  required_ruby_version: !ruby/object:Gem::Requirement
242
266
  requirements:
243
- - - "~>"
267
+ - - ">="
244
268
  - !ruby/object:Gem::Version
245
- version: '2.3'
269
+ version: '2.4'
246
270
  required_rubygems_version: !ruby/object:Gem::Requirement
247
271
  requirements:
248
272
  - - ">="
249
273
  - !ruby/object:Gem::Version
250
274
  version: '0'
251
275
  requirements: []
252
- rubygems_version: 3.0.6
253
- signing_key:
276
+ rubygems_version: 3.1.4
277
+ signing_key:
254
278
  specification_version: 4
255
279
  summary: Translate your Rails routes in a simple manner
256
280
  test_files: []