route_translator 5.1.0 → 5.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -47
- data/README.md +1 -1
- data/lib/route_translator.rb +1 -0
- data/lib/route_translator/extensions.rb +1 -0
- data/lib/route_translator/extensions/action_controller.rb +2 -8
- data/lib/route_translator/extensions/route_set.rb +1 -0
- data/lib/route_translator/host.rb +1 -0
- data/lib/route_translator/route.rb +1 -0
- data/lib/route_translator/translator.rb +4 -5
- data/lib/route_translator/translator/path.rb +1 -0
- data/lib/route_translator/translator/path/segment.rb +18 -6
- data/lib/route_translator/translator/route_helpers.rb +1 -0
- data/lib/route_translator/version.rb +1 -1
- metadata +32 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e052715e0f6568065a6752767ba185679e0b690
|
4
|
+
data.tar.gz: b53d37139709fc1786fed663161e64438d60fe9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87dbd3ae753dd22a43a4e3ceab878d20d30a640a46adbd5cb945592de108ad0bad55347246738f3f0faf21327044a6f236f164f4057bb459a12ca57b380f6a1c
|
7
|
+
data.tar.gz: 5e35380e56296c10c85ff144c525d32c5b8bfc7da17a87d1f13c93cb1839228004f907a5c7286ae923ae6770d3e441412635d2d463c474ec62e9f853384a918c
|
data/CHANGELOG.md
CHANGED
@@ -1,80 +1,96 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 5.
|
3
|
+
## 5.2.2 / 2017-03-21
|
4
4
|
|
5
|
-
*
|
6
|
-
* Update development dependencies
|
5
|
+
* [BUGFIX] Lock maximum Rails version to 5.1.0.beta1
|
7
6
|
|
8
|
-
## 5.
|
7
|
+
## 5.2.1 / 2017-03-09
|
9
8
|
|
10
|
-
*
|
11
|
-
*
|
12
|
-
* Improve Translator method
|
13
|
-
* Minor improvements
|
9
|
+
* [ENHANCEMENT] Use Ruby 2.3's Frozen String Literal Pragma
|
10
|
+
* [ENHANCEMENT] Minor improvements
|
14
11
|
|
15
|
-
## 5.0
|
12
|
+
## 5.2.0 / 2017-03-08
|
16
13
|
|
17
|
-
*
|
18
|
-
*
|
14
|
+
* [FEATURE] Rails 5.1 compatibility
|
15
|
+
* [BUGFIX] Do not change I18n.default_locale
|
16
|
+
* [ENHANCEMENT] Cleanup test suite
|
17
|
+
* [ENHANCEMENT] Follow Vandamme's changelog conventions
|
19
18
|
|
20
|
-
## 5.0
|
19
|
+
## 5.1.0 / 2017-01-24
|
21
20
|
|
22
|
-
*
|
21
|
+
* [FEATURE] Translate controllers with namespaces (#120)
|
22
|
+
* [ENHANCEMENT] Update development dependencies
|
23
23
|
|
24
|
-
## 5.0.
|
24
|
+
## 5.0.6 / 2017-01-17
|
25
25
|
|
26
|
-
*
|
27
|
-
*
|
26
|
+
* [PERFORMANCE] Improve Translator method
|
27
|
+
* [ENHANCEMENT] Test against Ruby 2.4.0
|
28
|
+
* [ENHANCEMENT] Update copyright in LICENSE
|
29
|
+
* [ENHANCEMENT] Minor improvements
|
28
30
|
|
29
|
-
## 5.0.
|
31
|
+
## 5.0.5 / 2016-12-15
|
30
32
|
|
31
|
-
*
|
32
|
-
*
|
33
|
+
* [BUGFIX] Fix generated prefix to localized one (#123)
|
34
|
+
* [PERFORMANCE] Improve Mapper's monkey patch
|
33
35
|
|
34
|
-
## 5.0.
|
36
|
+
## 5.0.4 / 2016-11-11
|
35
37
|
|
36
|
-
*
|
37
|
-
* Update development dependencies
|
38
|
+
* [BUGFIX] Retain value of options_constraints if callable
|
38
39
|
|
39
|
-
## 5.0.
|
40
|
+
## 5.0.3 / 2016-11-01
|
40
41
|
|
41
|
-
*
|
42
|
+
* [BUGFIX] Fix issue with callable constraints
|
43
|
+
* [ENHANCEMENT] Update development dependencies
|
42
44
|
|
43
|
-
##
|
45
|
+
## 5.0.2 / 2016-08-02
|
44
46
|
|
45
|
-
*
|
46
|
-
*
|
47
|
-
* Update development dependencies
|
47
|
+
* [BUGFIX] Replace around_filter with around_action
|
48
|
+
* [ENHANCEMENT] Update development dependencies
|
48
49
|
|
49
|
-
##
|
50
|
+
## 5.0.1 / 2016-07-14
|
50
51
|
|
51
|
-
*
|
52
|
+
* [ENHANCEMENT] Add private keyword in Segment module
|
53
|
+
* [ENHANCEMENT] Update development dependencies
|
52
54
|
|
53
|
-
##
|
55
|
+
## 5.0.0 / 2016-07-01
|
54
56
|
|
55
|
-
*
|
56
|
-
* Improve TestCase helpers test
|
57
|
+
* [FEATURE] Rails 5 compatibility
|
57
58
|
|
58
|
-
## 4.
|
59
|
+
## 4.4.0 / 2016-07-01
|
59
60
|
|
60
|
-
*
|
61
|
-
*
|
61
|
+
* [FEATURE] Support custom locale path segments, i.e. /uk/en/widgets
|
62
|
+
* [ENHANCEMENT] Using AS::Concern instead of monkey patching ActionController
|
63
|
+
* [ENHANCEMENT] Update development dependencies
|
62
64
|
|
63
|
-
## 4.
|
65
|
+
## 4.3.0 / 2016-03-03
|
64
66
|
|
65
|
-
*
|
67
|
+
* [PERFORMANCE] Refactor translator module
|
66
68
|
|
67
|
-
## 4.2.
|
69
|
+
## 4.2.5 / 2016-02-11
|
68
70
|
|
69
|
-
*
|
70
|
-
* Improve
|
71
|
+
* [BUGFIX] Generate correct route when a segment is preceded by a dot (#132)
|
72
|
+
* [ENHANCEMENT] Improve TestCase helpers test
|
71
73
|
|
72
|
-
## 4.2.
|
74
|
+
## 4.2.4 / 2016-02-04
|
73
75
|
|
74
|
-
*
|
76
|
+
* [BUGFIX] Change how helpers are loaded in TestCase
|
77
|
+
* [ENHANCEMENT] Update dependencies
|
75
78
|
|
76
|
-
## 4.2.
|
79
|
+
## 4.2.3 / 2016-01-15
|
77
80
|
|
78
|
-
*
|
79
|
-
|
80
|
-
|
81
|
+
* [PERFORMANCE] Minor tweaks
|
82
|
+
|
83
|
+
## 4.2.2 / 2015-12-16
|
84
|
+
|
85
|
+
* [BUGFIX] Fix native path generation with host_locale (#95)
|
86
|
+
* [ENHANCEMENT] Improve tests
|
87
|
+
|
88
|
+
## 4.2.1 / 2015-12-15
|
89
|
+
|
90
|
+
* [BUGFIX] Fix gemspec
|
91
|
+
|
92
|
+
## 4.2.0 / 2015-12-15
|
93
|
+
|
94
|
+
* [ENHANCEMENT] Style update to match RuboCop recommandations
|
95
|
+
* [BUGFIX] Permit named_params with suffix (#116)
|
96
|
+
* [BUGFIX] Fix optional parameters with prefix (#118)
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ RouteTranslator is a gem to allow you to manage the translations of your app rou
|
|
10
10
|
|
11
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).
|
12
12
|
|
13
|
-
Right now it works with Rails 5.0
|
13
|
+
Right now it works with Rails 5.0/5.1
|
14
14
|
|
15
15
|
|
16
16
|
|
data/lib/route_translator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'action_controller'
|
2
3
|
require 'active_support/concern'
|
3
4
|
|
@@ -12,13 +13,7 @@ module RouteTranslator
|
|
12
13
|
private
|
13
14
|
|
14
15
|
def set_locale_from_url
|
15
|
-
|
16
|
-
if tmp_default_locale
|
17
|
-
current_default_locale = I18n.default_locale
|
18
|
-
I18n.default_locale = tmp_default_locale
|
19
|
-
end
|
20
|
-
|
21
|
-
tmp_locale = params[RouteTranslator.locale_param_key] || tmp_default_locale
|
16
|
+
tmp_locale = params[RouteTranslator.locale_param_key] || RouteTranslator::Host.locale_from_host(request.host)
|
22
17
|
if tmp_locale
|
23
18
|
current_locale = I18n.locale
|
24
19
|
I18n.locale = tmp_locale
|
@@ -27,7 +22,6 @@ module RouteTranslator
|
|
27
22
|
yield
|
28
23
|
|
29
24
|
ensure
|
30
|
-
I18n.default_locale = current_default_locale if tmp_default_locale
|
31
25
|
I18n.locale = current_locale if tmp_locale
|
32
26
|
end
|
33
27
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
2
|
require File.expand_path('../translator/route_helpers', __FILE__)
|
4
3
|
require File.expand_path('../translator/path', __FILE__)
|
5
4
|
require File.expand_path('../route', __FILE__)
|
@@ -9,8 +8,9 @@ module RouteTranslator
|
|
9
8
|
class << self
|
10
9
|
private
|
11
10
|
|
12
|
-
def
|
13
|
-
|
11
|
+
def locale_from_args(args)
|
12
|
+
args_hash = args.detect { |arg| arg.is_a?(Hash) }
|
13
|
+
args_hash[:locale] if RouteTranslator.config.host_locales.present? && args_hash
|
14
14
|
end
|
15
15
|
|
16
16
|
def translate_name(name, locale, named_routes_names)
|
@@ -75,8 +75,7 @@ module RouteTranslator
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def route_name_for(args, old_name, suffix, kaller)
|
78
|
-
|
79
|
-
args_locale = host_locales_option? && args_hash && args_hash[:locale]
|
78
|
+
args_locale = locale_from_args(args)
|
80
79
|
current_locale_name = I18n.locale.to_s.underscore
|
81
80
|
|
82
81
|
locale = if args_locale
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module RouteTranslator
|
2
3
|
module Translator
|
3
4
|
module Path
|
@@ -13,8 +14,14 @@ module RouteTranslator
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def translatable_segment(segment)
|
18
|
+
matches = TRANSLATABLE_SEGMENT.match(segment)
|
19
|
+
matches[1] if matches.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
def translate_resource(str, locale, scope)
|
17
23
|
handler = proc { |exception| exception }
|
24
|
+
opts = { locale: locale, scope: scope }
|
18
25
|
|
19
26
|
if I18n.translate(str, opts.merge(exception_handler: handler)).is_a?(I18n::MissingTranslation)
|
20
27
|
I18n.translate(str, opts.merge(fallback_options(str, locale)))
|
@@ -25,7 +32,7 @@ module RouteTranslator
|
|
25
32
|
|
26
33
|
def translate_string(str, locale, scope)
|
27
34
|
locale = locale.to_s.gsub('native_', '')
|
28
|
-
translated_resource = translate_resource(str, locale, scope
|
35
|
+
translated_resource = translate_resource(str, locale, scope)
|
29
36
|
|
30
37
|
URI.escape translated_resource
|
31
38
|
end
|
@@ -37,18 +44,23 @@ module RouteTranslator
|
|
37
44
|
#
|
38
45
|
# If the path segment contains something like an optional format
|
39
46
|
# "people(.:format)", only "people" will be translated.
|
47
|
+
# If the path contains a hyphenated suffix, it will be translated.
|
40
48
|
# If there is no translation, the path segment is blank, begins with a
|
41
49
|
# ":" (param key) or "*" (wildcard), the segment is returned untouched.
|
42
50
|
def translate(segment, locale, scope)
|
43
51
|
return segment if segment.empty?
|
44
|
-
|
45
|
-
|
52
|
+
|
53
|
+
if segment.starts_with?(':'.freeze)
|
54
|
+
named_param, hyphenized = segment.split('-'.freeze, 2)
|
55
|
+
return "#{named_param}-#{translate(hyphenized, locale, scope)}" if hyphenized
|
56
|
+
end
|
57
|
+
|
46
58
|
return segment if segment.starts_with?('('.freeze) || segment.starts_with?('*'.freeze) || segment.include?(':'.freeze)
|
47
59
|
|
48
60
|
appended_part = segment.slice!(/(\()$/)
|
49
|
-
|
61
|
+
str = translatable_segment(segment)
|
50
62
|
|
51
|
-
(translate_string(
|
63
|
+
(translate_string(str, locale, scope) || segment) + appended_part.to_s
|
52
64
|
end
|
53
65
|
end
|
54
66
|
end
|
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: 5.
|
4
|
+
version: 5.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geremia Taglialatela
|
@@ -10,36 +10,48 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 5.0.0.1
|
22
|
+
- - "<="
|
20
23
|
- !ruby/object:Gem::Version
|
21
|
-
version: 5.0.
|
24
|
+
version: 5.1.0.beta1
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
|
-
- - "
|
29
|
+
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
|
-
version: 5.0.0
|
31
|
+
version: 5.0.0.1
|
32
|
+
- - "<="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 5.1.0.beta1
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: actionpack
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
32
38
|
requirements:
|
33
|
-
- - "
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 5.0.0.1
|
42
|
+
- - "<="
|
34
43
|
- !ruby/object:Gem::Version
|
35
|
-
version: 5.0.
|
44
|
+
version: 5.1.0.beta1
|
36
45
|
type: :runtime
|
37
46
|
prerelease: false
|
38
47
|
version_requirements: !ruby/object:Gem::Requirement
|
39
48
|
requirements:
|
40
|
-
- - "
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 5.0.0.1
|
52
|
+
- - "<="
|
41
53
|
- !ruby/object:Gem::Version
|
42
|
-
version: 5.0.
|
54
|
+
version: 5.1.0.beta1
|
43
55
|
- !ruby/object:Gem::Dependency
|
44
56
|
name: appraisal
|
45
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,16 +112,22 @@ dependencies:
|
|
100
112
|
name: rails
|
101
113
|
requirement: !ruby/object:Gem::Requirement
|
102
114
|
requirements:
|
103
|
-
- - "
|
115
|
+
- - ">="
|
104
116
|
- !ruby/object:Gem::Version
|
105
|
-
version: 5.0.0
|
117
|
+
version: 5.0.0.1
|
118
|
+
- - "<="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 5.1.0.beta1
|
106
121
|
type: :development
|
107
122
|
prerelease: false
|
108
123
|
version_requirements: !ruby/object:Gem::Requirement
|
109
124
|
requirements:
|
110
|
-
- - "
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 5.0.0.1
|
128
|
+
- - "<="
|
111
129
|
- !ruby/object:Gem::Version
|
112
|
-
version: 5.0.
|
130
|
+
version: 5.1.0.beta1
|
113
131
|
- !ruby/object:Gem::Dependency
|
114
132
|
name: rake
|
115
133
|
requirement: !ruby/object:Gem::Requirement
|