rails-localization 1.2.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/Gemfile +6 -8
- data/Gemfile.lock +157 -124
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rails-localization.rb +4 -5
- data/lib/rails-localization/controller.rb +5 -5
- data/lib/rails-localization/i18n.rb +3 -5
- data/lib/rails-localization/router.rb +10 -12
- data/lib/rails-localization/url_helper.rb +38 -0
- data/rails-localization.gemspec +23 -24
- data/test/i18n_integration_test.rb +9 -9
- data/test/mapper_integration_test.rb +8 -8
- data/test/rails-localization_test.rb +16 -7
- data/test/test_app/Gemfile +2 -2
- data/test/test_app/Gemfile.lock +113 -79
- data/test/test_app/app/controllers/main_controller.rb +2 -2
- data/test/test_app/app/controllers/sub_app/main_controller.rb +3 -3
- data/test/test_app/app/controllers/users_controller.rb +4 -5
- data/test/test_app/config/initializers/secret_token.rb +1 -1
- data/test/test_app/config/routes.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/urls_overwriting_test.rb +7 -2
- metadata +20 -21
- data/lib/rails-localization/route_set.rb +0 -12
- data/lib/rails-localization/url_options.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e65d3048e387337c90471103e9ec38a17c626f6c6fc85dd73b2005e2f027ab60
|
4
|
+
data.tar.gz: b9c6e5fca7270275eb8a7b2fb7eeb5fa7d6e23d95f59b5b4eef9358c5f7d4b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2897451f27d2f64286f03d8df531b87652a5aadb3e290956d037245b00149eaf22e3c4099d60e0f7fd59ad687c704e5bce27969913746a08802bbdb8cbf2121d
|
7
|
+
data.tar.gz: 18755b927df0bb3ee81d25a85506864009cca774bfb376346faa51e9b534e6c4e98fc9380133bc64d9d7790e6f0ad689fe92f40f9d5544bccecba6308c295037
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.1
|
data/Gemfile
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem "rails", ">=
|
3
|
+
gem "rails", ">= 5.0.0"
|
4
4
|
gem "i18n"
|
5
5
|
|
6
6
|
group :debug do
|
7
|
-
gem
|
7
|
+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
8
|
+
#gem "byebug", platform: :ruby_20
|
8
9
|
#gem "debugger", "~> 1.2.2", platform: :ruby_19
|
9
10
|
#gem "ruby-debug", platform: :ruby_18
|
10
11
|
end
|
11
12
|
|
12
13
|
group :development, :test do
|
13
|
-
gem "jeweler", "~>
|
14
|
+
gem "jeweler", "~> 2.3"
|
14
15
|
end
|
15
16
|
|
16
17
|
group :debug, :test do
|
17
|
-
gem "yard"
|
18
|
-
gem "redcarpet"
|
18
|
+
gem "yard"
|
19
19
|
end
|
20
20
|
|
21
21
|
group :test do
|
22
22
|
gem 'minitest'
|
23
23
|
gem "test-unit"
|
24
|
-
gem 'shoulda-context'
|
25
|
-
gem 'shoulda-matchers'
|
26
24
|
|
27
25
|
gem "capybara"
|
28
|
-
end
|
26
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,134 +1,167 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
actionpack (=
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
4
|
+
actioncable (5.2.0)
|
5
|
+
actionpack (= 5.2.0)
|
6
|
+
nio4r (~> 2.0)
|
7
|
+
websocket-driver (>= 0.6.1)
|
8
|
+
actionmailer (5.2.0)
|
9
|
+
actionpack (= 5.2.0)
|
10
|
+
actionview (= 5.2.0)
|
11
|
+
activejob (= 5.2.0)
|
12
|
+
mail (~> 2.5, >= 2.5.4)
|
13
|
+
rails-dom-testing (~> 2.0)
|
14
|
+
actionpack (5.2.0)
|
15
|
+
actionview (= 5.2.0)
|
16
|
+
activesupport (= 5.2.0)
|
17
|
+
rack (~> 2.0)
|
18
|
+
rack-test (>= 0.6.3)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
21
|
+
actionview (5.2.0)
|
22
|
+
activesupport (= 5.2.0)
|
23
|
+
builder (~> 3.1)
|
24
|
+
erubi (~> 1.4)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
27
|
+
activejob (5.2.0)
|
28
|
+
activesupport (= 5.2.0)
|
29
|
+
globalid (>= 0.3.6)
|
30
|
+
activemodel (5.2.0)
|
31
|
+
activesupport (= 5.2.0)
|
32
|
+
activerecord (5.2.0)
|
33
|
+
activemodel (= 5.2.0)
|
34
|
+
activesupport (= 5.2.0)
|
35
|
+
arel (>= 9.0)
|
36
|
+
activestorage (5.2.0)
|
37
|
+
actionpack (= 5.2.0)
|
38
|
+
activerecord (= 5.2.0)
|
39
|
+
marcel (~> 0.3.1)
|
40
|
+
activesupport (5.2.0)
|
41
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
42
|
+
i18n (>= 0.7, < 2)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
tzinfo (~> 1.1)
|
45
|
+
addressable (2.4.0)
|
46
|
+
arel (9.0.0)
|
47
|
+
builder (3.2.3)
|
48
|
+
byebug (10.0.2)
|
49
|
+
capybara (3.3.1)
|
48
50
|
addressable
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
mini_mime (>= 0.1.3)
|
52
|
+
nokogiri (~> 1.8)
|
53
|
+
rack (>= 1.6.0)
|
54
|
+
rack-test (>= 0.6.3)
|
55
|
+
xpath (~> 3.1)
|
56
|
+
concurrent-ruby (1.0.5)
|
57
|
+
crass (1.0.4)
|
58
|
+
descendants_tracker (0.0.4)
|
59
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
60
|
+
erubi (1.7.1)
|
61
|
+
faraday (0.9.2)
|
62
|
+
multipart-post (>= 1.2, < 3)
|
63
|
+
git (1.4.0)
|
64
|
+
github_api (0.16.0)
|
65
|
+
addressable (~> 2.4.0)
|
66
|
+
descendants_tracker (~> 0.0.4)
|
67
|
+
faraday (~> 0.8, < 0.10)
|
68
|
+
hashie (>= 3.4)
|
69
|
+
mime-types (>= 1.16, < 3.0)
|
70
|
+
oauth2 (~> 1.0)
|
71
|
+
globalid (0.4.1)
|
72
|
+
activesupport (>= 4.2.0)
|
73
|
+
hashie (3.5.7)
|
74
|
+
highline (2.0.0)
|
75
|
+
i18n (1.0.1)
|
76
|
+
concurrent-ruby (~> 1.0)
|
77
|
+
jeweler (2.3.9)
|
60
78
|
builder
|
61
|
-
bundler
|
79
|
+
bundler
|
62
80
|
git (>= 1.2.5)
|
63
|
-
github_api (
|
81
|
+
github_api (~> 0.16.0)
|
64
82
|
highline (>= 1.6.15)
|
65
|
-
nokogiri (
|
83
|
+
nokogiri (>= 1.5.10)
|
84
|
+
psych
|
66
85
|
rake
|
67
86
|
rdoc
|
68
|
-
|
69
|
-
jwt (
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
semver2
|
88
|
+
jwt (1.5.6)
|
89
|
+
loofah (2.2.2)
|
90
|
+
crass (~> 1.0.2)
|
91
|
+
nokogiri (>= 1.5.9)
|
92
|
+
mail (2.7.0)
|
93
|
+
mini_mime (>= 0.1.1)
|
94
|
+
marcel (0.3.2)
|
95
|
+
mimemagic (~> 0.3.2)
|
96
|
+
method_source (0.9.0)
|
97
|
+
mime-types (2.99.3)
|
98
|
+
mimemagic (0.3.2)
|
99
|
+
mini_mime (1.0.0)
|
100
|
+
mini_portile2 (2.3.0)
|
101
|
+
minitest (5.11.3)
|
102
|
+
multi_json (1.13.1)
|
103
|
+
multi_xml (0.6.0)
|
104
|
+
multipart-post (2.0.0)
|
105
|
+
nio4r (2.3.1)
|
106
|
+
nokogiri (1.8.4)
|
107
|
+
mini_portile2 (~> 2.3.0)
|
108
|
+
oauth2 (1.4.0)
|
109
|
+
faraday (>= 0.8, < 0.13)
|
110
|
+
jwt (~> 1.0)
|
111
|
+
multi_json (~> 1.3)
|
85
112
|
multi_xml (~> 0.5)
|
86
|
-
rack (
|
87
|
-
|
88
|
-
|
89
|
-
rack
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
activesupport (=
|
113
|
+
rack (>= 1.2, < 3)
|
114
|
+
power_assert (1.1.3)
|
115
|
+
psych (3.0.2)
|
116
|
+
rack (2.0.5)
|
117
|
+
rack-test (1.0.0)
|
118
|
+
rack (>= 1.0, < 3)
|
119
|
+
rails (5.2.0)
|
120
|
+
actioncable (= 5.2.0)
|
121
|
+
actionmailer (= 5.2.0)
|
122
|
+
actionpack (= 5.2.0)
|
123
|
+
actionview (= 5.2.0)
|
124
|
+
activejob (= 5.2.0)
|
125
|
+
activemodel (= 5.2.0)
|
126
|
+
activerecord (= 5.2.0)
|
127
|
+
activestorage (= 5.2.0)
|
128
|
+
activesupport (= 5.2.0)
|
129
|
+
bundler (>= 1.3.0)
|
130
|
+
railties (= 5.2.0)
|
131
|
+
sprockets-rails (>= 2.0.0)
|
132
|
+
rails-dom-testing (2.0.3)
|
133
|
+
activesupport (>= 4.2.0)
|
134
|
+
nokogiri (>= 1.6)
|
135
|
+
rails-html-sanitizer (1.0.4)
|
136
|
+
loofah (~> 2.2, >= 2.2.2)
|
137
|
+
railties (5.2.0)
|
138
|
+
actionpack (= 5.2.0)
|
139
|
+
activesupport (= 5.2.0)
|
140
|
+
method_source
|
102
141
|
rake (>= 0.8.7)
|
103
142
|
thor (>= 0.18.1, < 2.0)
|
104
|
-
rake (
|
105
|
-
rdoc (
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
polyglot
|
127
|
-
polyglot (>= 0.3.1)
|
128
|
-
tzinfo (0.3.38)
|
129
|
-
xpath (2.0.0)
|
130
|
-
nokogiri (~> 1.3)
|
131
|
-
yard (0.8.7.3)
|
143
|
+
rake (12.3.1)
|
144
|
+
rdoc (6.0.4)
|
145
|
+
semver2 (3.4.2)
|
146
|
+
sprockets (3.7.2)
|
147
|
+
concurrent-ruby (~> 1.0)
|
148
|
+
rack (> 1, < 3)
|
149
|
+
sprockets-rails (3.2.1)
|
150
|
+
actionpack (>= 4.0)
|
151
|
+
activesupport (>= 4.0)
|
152
|
+
sprockets (>= 3.0.0)
|
153
|
+
test-unit (3.2.8)
|
154
|
+
power_assert
|
155
|
+
thor (0.20.0)
|
156
|
+
thread_safe (0.3.6)
|
157
|
+
tzinfo (1.2.5)
|
158
|
+
thread_safe (~> 0.1)
|
159
|
+
websocket-driver (0.7.0)
|
160
|
+
websocket-extensions (>= 0.1.0)
|
161
|
+
websocket-extensions (0.1.3)
|
162
|
+
xpath (3.1.0)
|
163
|
+
nokogiri (~> 1.8)
|
164
|
+
yard (0.9.15)
|
132
165
|
|
133
166
|
PLATFORMS
|
134
167
|
ruby
|
@@ -137,11 +170,11 @@ DEPENDENCIES
|
|
137
170
|
byebug
|
138
171
|
capybara
|
139
172
|
i18n
|
140
|
-
jeweler (~>
|
173
|
+
jeweler (~> 2.3)
|
141
174
|
minitest
|
142
|
-
rails (>=
|
143
|
-
redcarpet
|
144
|
-
shoulda-context
|
145
|
-
shoulda-matchers
|
175
|
+
rails (>= 5.0.0)
|
146
176
|
test-unit
|
147
177
|
yard
|
178
|
+
|
179
|
+
BUNDLED WITH
|
180
|
+
1.16.2
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
2.1.0
|
data/lib/rails-localization.rb
CHANGED
@@ -5,16 +5,15 @@ require 'rails-localization/engine'
|
|
5
5
|
|
6
6
|
if defined?(ActiveSupport)
|
7
7
|
require 'rails-localization/i18n'
|
8
|
-
require 'rails-localization/url_options'
|
9
8
|
|
10
9
|
I18n.extend RailsLocalization::I18n
|
11
10
|
|
12
11
|
ActiveSupport.on_load(:before_configuration) do
|
13
12
|
require 'rails-localization/router'
|
14
|
-
require 'rails-localization/
|
13
|
+
require 'rails-localization/url_helper'
|
15
14
|
|
16
|
-
ActionDispatch::Routing::RouteSet.send :
|
17
|
-
ActionDispatch::Routing::Mapper.send :
|
15
|
+
ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.send :prepend, RailsLocalization::UrlHelper
|
16
|
+
ActionDispatch::Routing::Mapper.send :prepend, ActionDispatch::Routing::Mapper::Localization
|
18
17
|
|
19
18
|
ActiveSupport.on_load(:action_controller) do
|
20
19
|
require 'rails-localization/controller'
|
@@ -23,4 +22,4 @@ if defined?(ActiveSupport)
|
|
23
22
|
end
|
24
23
|
else
|
25
24
|
warn "ActiveSupport is not defined. Ignoring RailsLocalization loading"
|
26
|
-
end
|
25
|
+
end
|
@@ -2,7 +2,7 @@ module RailsLocalization
|
|
2
2
|
module Controller
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
|
-
|
5
|
+
around_action :process_with_locale
|
6
6
|
|
7
7
|
protected
|
8
8
|
|
@@ -12,11 +12,11 @@ module RailsLocalization
|
|
12
12
|
::I18n.locale = params[:locale].blank? ? ::I18n.default_locale : params[:locale].to_s
|
13
13
|
end
|
14
14
|
yield
|
15
|
-
ensure
|
15
|
+
ensure
|
16
16
|
::I18n.locale = ::I18n.default_locale
|
17
|
-
end
|
18
|
-
end
|
17
|
+
end
|
18
|
+
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module ActionDispatch::Routing::Mapper::Localization
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
scope("(:locale)", constraints: {locale: /#{locales.keys.join('|')}/}, defaults: {locale: ""}) { yield }
|
12
|
-
end
|
2
|
+
def localized(*locales)
|
3
|
+
symbolized_locales = locales.map(&:to_sym)
|
4
|
+
I18n.config.available_locales = symbolized_locales
|
5
|
+
if @set == Rails.application.routes
|
6
|
+
I18n.route_locales[:main_app] = symbolized_locales
|
7
|
+
else
|
8
|
+
sub_app_name = @scope[:module] || :main_app
|
9
|
+
I18n.route_locales[sub_app_name] = symbolized_locales
|
13
10
|
end
|
11
|
+
scope("(:locale)", constraints: {locale: /#{symbolized_locales.join('|')}/}, defaults: {locale: ""}) { yield }
|
14
12
|
end
|
15
|
-
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RailsLocalization
|
2
|
+
module UrlHelper
|
3
|
+
def handle_positional_args(controller_options, inner_options, args, result, path_params)
|
4
|
+
options = super
|
5
|
+
|
6
|
+
if options[:_recall] && options[:_recall].has_key?(:locale) && path_params.include?(:locale)
|
7
|
+
if inner_options.has_key?(:locale) && inner_options[:locale].blank?
|
8
|
+
options.delete(:locale)
|
9
|
+
else
|
10
|
+
if inner_options[:locale] && ::I18n.config.available_locales.include?(inner_options[:locale].to_sym)
|
11
|
+
if inner_options[:locale].to_s != ::I18n.default_locale.to_s
|
12
|
+
options[:locale] = inner_options[:locale]
|
13
|
+
else
|
14
|
+
options.delete(:locale)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
if ::I18n.locale.to_s != ::I18n.default_locale.to_s
|
18
|
+
options[:locale] = ::I18n.locale.to_s
|
19
|
+
else
|
20
|
+
options.delete(:locale)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if options.has_key?(:locale) && !inner_options.has_key?(:locale) && !path_params.include?(:locale)
|
27
|
+
options.delete(:locale)
|
28
|
+
end
|
29
|
+
|
30
|
+
if options.has_key?(:_positional_keys) && options[:_positional_keys].includes?(:locale)
|
31
|
+
i = options[:_positional_keys].index(:locale)
|
32
|
+
options[:_positional_args].insert(i, (options.delete(:locale) || ::I18n.locale.to_s))
|
33
|
+
end
|
34
|
+
|
35
|
+
options
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/rails-localization.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: rails-localization 1.
|
5
|
+
# stub: rails-localization 2.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "rails-localization"
|
9
|
-
s.version = "1.
|
8
|
+
s.name = "rails-localization".freeze
|
9
|
+
s.version = "2.1.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["E-Max"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "This gem allows you to localize your rails application with ease"
|
16
|
-
s.email = "max@studentify.nl"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["E-Max".freeze]
|
14
|
+
s.date = "2018-08-06"
|
15
|
+
s.description = "This gem allows you to localize your rails application with ease".freeze
|
16
|
+
s.email = "max@studentify.nl".freeze
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt",
|
19
19
|
"README.rdoc"
|
@@ -33,9 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/rails-localization/controller.rb",
|
34
34
|
"lib/rails-localization/engine.rb",
|
35
35
|
"lib/rails-localization/i18n.rb",
|
36
|
-
"lib/rails-localization/route_set.rb",
|
37
36
|
"lib/rails-localization/router.rb",
|
38
|
-
"lib/rails-localization/
|
37
|
+
"lib/rails-localization/url_helper.rb",
|
39
38
|
"lib/rails_localization.rb",
|
40
39
|
"rails-localization.gemspec",
|
41
40
|
"test/i18n_integration_test.rb",
|
@@ -83,27 +82,27 @@ Gem::Specification.new do |s|
|
|
83
82
|
"test/test_helper.rb",
|
84
83
|
"test/urls_overwriting_test.rb"
|
85
84
|
]
|
86
|
-
s.homepage = "http://github.com/kot-begemot/rails-localization"
|
87
|
-
s.licenses = ["MIT"]
|
88
|
-
s.rubygems_version = "2.
|
89
|
-
s.summary = "Rails localization Gem"
|
85
|
+
s.homepage = "http://github.com/kot-begemot/rails-localization".freeze
|
86
|
+
s.licenses = ["MIT".freeze]
|
87
|
+
s.rubygems_version = "2.7.7".freeze
|
88
|
+
s.summary = "Rails localization Gem".freeze
|
90
89
|
|
91
90
|
if s.respond_to? :specification_version then
|
92
91
|
s.specification_version = 4
|
93
92
|
|
94
93
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
95
|
-
s.add_runtime_dependency(%q<rails
|
96
|
-
s.add_runtime_dependency(%q<i18n
|
97
|
-
s.add_development_dependency(%q<jeweler
|
94
|
+
s.add_runtime_dependency(%q<rails>.freeze, [">= 5.0.0"])
|
95
|
+
s.add_runtime_dependency(%q<i18n>.freeze, [">= 0"])
|
96
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
98
97
|
else
|
99
|
-
s.add_dependency(%q<rails
|
100
|
-
s.add_dependency(%q<i18n
|
101
|
-
s.add_dependency(%q<jeweler
|
98
|
+
s.add_dependency(%q<rails>.freeze, [">= 5.0.0"])
|
99
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
100
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
102
101
|
end
|
103
102
|
else
|
104
|
-
s.add_dependency(%q<rails
|
105
|
-
s.add_dependency(%q<i18n
|
106
|
-
s.add_dependency(%q<jeweler
|
103
|
+
s.add_dependency(%q<rails>.freeze, [">= 5.0.0"])
|
104
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
105
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
107
106
|
end
|
108
107
|
end
|
109
108
|
|
@@ -5,24 +5,24 @@ I18n.extend RailsLocalization::I18n
|
|
5
5
|
|
6
6
|
class I18nIntegrationTest < Test::Unit::TestCase
|
7
7
|
setup do
|
8
|
-
@i18n_locales = I18n.instance_variable_get(:@
|
9
|
-
I18n.instance_variable_set(:@
|
8
|
+
@i18n_locales = I18n.instance_variable_get(:@route_locales)
|
9
|
+
I18n.instance_variable_set(:@route_locales, nil)
|
10
10
|
end
|
11
11
|
|
12
12
|
teardown do
|
13
|
-
I18n.instance_variable_set(:@
|
13
|
+
I18n.instance_variable_set(:@route_locales, @i18n_locales)
|
14
14
|
end
|
15
15
|
|
16
|
-
test "should Respond to locales" do
|
17
|
-
assert_respond_to I18n, :
|
16
|
+
test "should Respond to locales" do
|
17
|
+
assert_respond_to I18n, :route_locales
|
18
18
|
end
|
19
19
|
|
20
20
|
test "should Return locales" do
|
21
|
-
I18n.instance_variable_set(:@
|
22
|
-
assert_equal(
|
21
|
+
I18n.instance_variable_set(:@route_locales, ["en"])
|
22
|
+
assert_equal(["en"], I18n.route_locales)
|
23
23
|
end
|
24
24
|
|
25
25
|
test "should Return empty hash if no locales" do
|
26
|
-
assert_equal({}, I18n.
|
26
|
+
assert_equal({}, I18n.route_locales)
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path("test_helper", File.dirname(__FILE__))
|
3
|
+
require File.expand_path("support/capybara_helper", File.dirname(__FILE__))
|
3
4
|
require "action_dispatch"
|
4
5
|
require 'active_support/core_ext'
|
5
6
|
require 'rails-localization/router'
|
@@ -10,12 +11,12 @@ ActionDispatch::Routing::Mapper.send :include, ActionDispatch::Routing::Mapper::
|
|
10
11
|
class MapperIntegrationTest < Test::Unit::TestCase
|
11
12
|
setup do
|
12
13
|
@route_set = ActionDispatch::Routing::RouteSet.new
|
13
|
-
@i18n_locales = I18n.instance_variable_get(:@
|
14
|
-
I18n.instance_variable_set(:@
|
14
|
+
@i18n_locales = I18n.instance_variable_get(:@route_locales)
|
15
|
+
I18n.instance_variable_set(:@route_locales, nil)
|
15
16
|
end
|
16
17
|
|
17
18
|
teardown do
|
18
|
-
I18n.instance_variable_set(:@
|
19
|
+
I18n.instance_variable_set(:@route_locales, @i18n_locales)
|
19
20
|
end
|
20
21
|
|
21
22
|
test "should Respond to localized" do
|
@@ -25,21 +26,20 @@ class MapperIntegrationTest < Test::Unit::TestCase
|
|
25
26
|
|
26
27
|
test "should Define locales for I18n" do
|
27
28
|
@route_set.draw do
|
28
|
-
localized(
|
29
|
+
localized("en") do; end
|
29
30
|
end
|
30
31
|
|
31
|
-
assert_kind_of(Hash, I18n.
|
32
|
+
assert_kind_of(Hash, I18n.route_locales[:main_app])
|
32
33
|
end
|
33
34
|
|
34
35
|
# test "should recognize path" do
|
35
36
|
# @route_set.draw do
|
36
|
-
# localized(
|
37
|
+
# localized("en") do
|
37
38
|
# resources :posts
|
38
39
|
# root :to => "welcome#index"
|
39
40
|
# end
|
40
41
|
# end
|
41
42
|
|
42
|
-
# assert_equal(
|
43
|
+
# assert_equal("en", @route_set.recognize_path("/", {:method => :get}))
|
43
44
|
# end
|
44
45
|
end
|
45
|
-
|
@@ -5,6 +5,15 @@ require File.expand_path("support/capybara_helper", File.dirname(__FILE__))
|
|
5
5
|
class RailsLocalizationTest < ActionDispatch::IntegrationTest
|
6
6
|
include CapybaraHelper
|
7
7
|
|
8
|
+
setup do
|
9
|
+
I18n.available_locales = [:en, :ru]
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
::I18n.locale = ::I18n.default_locale
|
14
|
+
I18n.available_locales = []
|
15
|
+
end
|
16
|
+
|
8
17
|
#context "sub app" do
|
9
18
|
test "should access without locale" do
|
10
19
|
visit "/sub"
|
@@ -81,7 +90,7 @@ class RailsLocalizationTest < ActionDispatch::IntegrationTest
|
|
81
90
|
assert_equal 200, page.status_code
|
82
91
|
assert page.has_content? "translation missing: en.main.index"
|
83
92
|
end
|
84
|
-
|
93
|
+
|
85
94
|
test "root page should access with english locale" do
|
86
95
|
visit "/en"
|
87
96
|
assert_equal 200, page.status_code
|
@@ -104,27 +113,27 @@ class RailsLocalizationTest < ActionDispatch::IntegrationTest
|
|
104
113
|
#end
|
105
114
|
|
106
115
|
#context "welcome page" do
|
107
|
-
|
116
|
+
test "page with locale 1 returns context" do
|
108
117
|
visit "/en/welcome"
|
109
118
|
assert_equal 200, page.status_code
|
110
119
|
assert page.has_content? "translation missing: en.main.welcome"
|
111
120
|
end
|
112
121
|
|
113
|
-
|
122
|
+
test "page with locale 2 returns context" do
|
114
123
|
visit "/ru/welcome"
|
115
124
|
assert_equal 200, page.status_code
|
116
125
|
assert page.has_content? "translation missing: ru.main.welcome"
|
117
126
|
end
|
118
127
|
#end
|
119
|
-
|
128
|
+
|
120
129
|
#context "404" do
|
121
|
-
|
130
|
+
test "wrong page without locale" do
|
122
131
|
assert_raise ActionController::RoutingError do
|
123
132
|
visit "/test"
|
124
133
|
end
|
125
134
|
end
|
126
135
|
|
127
|
-
|
136
|
+
test "wrong page with locale" do
|
128
137
|
assert_raise ActionController::RoutingError do
|
129
138
|
visit "en/test"
|
130
139
|
end
|
@@ -182,4 +191,4 @@ class RailsLocalizationTest < ActionDispatch::IntegrationTest
|
|
182
191
|
end
|
183
192
|
end
|
184
193
|
#end
|
185
|
-
end
|
194
|
+
end
|
data/test/test_app/Gemfile
CHANGED
data/test/test_app/Gemfile.lock
CHANGED
@@ -1,93 +1,127 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../..
|
3
3
|
specs:
|
4
|
-
rails-localization (1.
|
4
|
+
rails-localization (1.2.0)
|
5
5
|
i18n
|
6
|
-
rails (>=
|
6
|
+
rails (>= 5.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
actionpack (=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
activesupport (=
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
11
|
+
actioncable (5.2.0)
|
12
|
+
actionpack (= 5.2.0)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailer (5.2.0)
|
16
|
+
actionpack (= 5.2.0)
|
17
|
+
actionview (= 5.2.0)
|
18
|
+
activejob (= 5.2.0)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.2.0)
|
22
|
+
actionview (= 5.2.0)
|
23
|
+
activesupport (= 5.2.0)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.2.0)
|
29
|
+
activesupport (= 5.2.0)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.2.0)
|
35
|
+
activesupport (= 5.2.0)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.2.0)
|
38
|
+
activesupport (= 5.2.0)
|
39
|
+
activerecord (5.2.0)
|
40
|
+
activemodel (= 5.2.0)
|
41
|
+
activesupport (= 5.2.0)
|
42
|
+
arel (>= 9.0)
|
43
|
+
activestorage (5.2.0)
|
44
|
+
actionpack (= 5.2.0)
|
45
|
+
activerecord (= 5.2.0)
|
46
|
+
marcel (~> 0.3.1)
|
47
|
+
activesupport (5.2.0)
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
|
+
i18n (>= 0.7, < 2)
|
50
|
+
minitest (~> 5.1)
|
51
|
+
tzinfo (~> 1.1)
|
52
|
+
arel (9.0.0)
|
53
|
+
builder (3.2.3)
|
54
|
+
concurrent-ruby (1.0.5)
|
55
|
+
crass (1.0.4)
|
56
|
+
erubi (1.7.1)
|
57
|
+
globalid (0.4.1)
|
58
|
+
activesupport (>= 4.2.0)
|
59
|
+
i18n (1.0.1)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
loofah (2.2.2)
|
62
|
+
crass (~> 1.0.2)
|
63
|
+
nokogiri (>= 1.5.9)
|
64
|
+
mail (2.7.0)
|
65
|
+
mini_mime (>= 0.1.1)
|
66
|
+
marcel (0.3.2)
|
67
|
+
mimemagic (~> 0.3.2)
|
68
|
+
method_source (0.9.0)
|
69
|
+
mimemagic (0.3.2)
|
70
|
+
mini_mime (1.0.0)
|
71
|
+
mini_portile2 (2.3.0)
|
72
|
+
minitest (5.11.3)
|
73
|
+
nio4r (2.3.1)
|
74
|
+
nokogiri (1.8.4)
|
75
|
+
mini_portile2 (~> 2.3.0)
|
76
|
+
rack (2.0.5)
|
77
|
+
rack-test (1.0.0)
|
78
|
+
rack (>= 1.0, < 3)
|
79
|
+
rails (5.2.0)
|
80
|
+
actioncable (= 5.2.0)
|
81
|
+
actionmailer (= 5.2.0)
|
82
|
+
actionpack (= 5.2.0)
|
83
|
+
actionview (= 5.2.0)
|
84
|
+
activejob (= 5.2.0)
|
85
|
+
activemodel (= 5.2.0)
|
86
|
+
activerecord (= 5.2.0)
|
87
|
+
activestorage (= 5.2.0)
|
88
|
+
activesupport (= 5.2.0)
|
89
|
+
bundler (>= 1.3.0)
|
90
|
+
railties (= 5.2.0)
|
91
|
+
sprockets-rails (>= 2.0.0)
|
92
|
+
rails-dom-testing (2.0.3)
|
93
|
+
activesupport (>= 4.2.0)
|
94
|
+
nokogiri (>= 1.6)
|
95
|
+
rails-html-sanitizer (1.0.4)
|
96
|
+
loofah (~> 2.2, >= 2.2.2)
|
97
|
+
railties (5.2.0)
|
98
|
+
actionpack (= 5.2.0)
|
99
|
+
activesupport (= 5.2.0)
|
100
|
+
method_source
|
70
101
|
rake (>= 0.8.7)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
sprockets (
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
102
|
+
thor (>= 0.18.1, < 2.0)
|
103
|
+
rake (12.3.1)
|
104
|
+
sprockets (3.7.2)
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
rack (> 1, < 3)
|
107
|
+
sprockets-rails (3.2.1)
|
108
|
+
actionpack (>= 4.0)
|
109
|
+
activesupport (>= 4.0)
|
110
|
+
sprockets (>= 3.0.0)
|
111
|
+
thor (0.20.0)
|
112
|
+
thread_safe (0.3.6)
|
113
|
+
tzinfo (1.2.5)
|
114
|
+
thread_safe (~> 0.1)
|
115
|
+
websocket-driver (0.7.0)
|
116
|
+
websocket-extensions (>= 0.1.0)
|
117
|
+
websocket-extensions (0.1.3)
|
87
118
|
|
88
119
|
PLATFORMS
|
89
120
|
ruby
|
90
121
|
|
91
122
|
DEPENDENCIES
|
92
|
-
rails (>=
|
123
|
+
rails (>= 5.0.0)
|
93
124
|
rails-localization!
|
125
|
+
|
126
|
+
BUNDLED WITH
|
127
|
+
1.16.2
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class SubApp::MainController < ApplicationController
|
2
2
|
def print_redirect
|
3
|
-
render :
|
3
|
+
render plain: sub_app_engine.print_redirect_path
|
4
4
|
end
|
5
5
|
|
6
6
|
def index
|
7
|
-
render :
|
7
|
+
render plain: t('sub_app.main.index')
|
8
8
|
end
|
9
9
|
|
10
10
|
def welcome
|
11
|
-
render :
|
11
|
+
render plain: sub_app_engine.print_redirect_path(locale: :ru)
|
12
12
|
end
|
13
13
|
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
class UsersController < ApplicationController
|
2
2
|
def index
|
3
|
-
render :
|
3
|
+
render plain: t('users.index')
|
4
4
|
end
|
5
5
|
|
6
6
|
def with_locale
|
7
|
-
render :
|
7
|
+
render plain: users_path, layout: false
|
8
8
|
end
|
9
9
|
|
10
10
|
def without_locale
|
11
|
-
render :
|
11
|
+
render plain: users_path(:locale => false), layout: false
|
12
12
|
end
|
13
13
|
|
14
14
|
def with_defined_locale
|
15
|
-
render :
|
15
|
+
render plain: users_path(:locale => :ru), layout: false
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
@@ -4,4 +4,4 @@
|
|
4
4
|
# If you change this key, all old signed cookies will become invalid!
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
TestApp::Application.config.
|
7
|
+
TestApp::Application.config.secret_key_base = '2dfa87d4cd5809fc27fae79627ad5203edbc35bad2a5730fe5ef969f0ef736a798480f49e8cfccc9b25f7e12d8ab500d619d4fbe572da497380293fba0c99975'
|
data/test/test_helper.rb
CHANGED
@@ -3,8 +3,13 @@ require File.expand_path("test_helper", File.dirname(__FILE__))
|
|
3
3
|
require File.expand_path("support/capybara_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class UrlsOverwritingTest < ActionController::TestCase
|
6
|
-
|
6
|
+
setup do
|
7
|
+
I18n.available_locales = [:en, :ru]
|
8
|
+
end
|
9
|
+
|
10
|
+
teardown do
|
7
11
|
::I18n.locale = ::I18n.default_locale
|
12
|
+
I18n.available_locales = []
|
8
13
|
end
|
9
14
|
|
10
15
|
test "root" do
|
@@ -15,4 +20,4 @@ class UrlsOverwritingTest < ActionController::TestCase
|
|
15
20
|
::I18n.locale = :ru
|
16
21
|
assert_generates("/ru", :controller => "main", :action => "index", :locale => "ru")
|
17
22
|
end
|
18
|
-
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-localization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E-Max
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: jeweler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '2.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '2.3'
|
55
55
|
description: This gem allows you to localize your rails application with ease
|
56
56
|
email: max@studentify.nl
|
57
57
|
executables: []
|
@@ -60,10 +60,10 @@ extra_rdoc_files:
|
|
60
60
|
- LICENSE.txt
|
61
61
|
- README.rdoc
|
62
62
|
files:
|
63
|
-
- .document
|
64
|
-
- .ruby-gemset
|
65
|
-
- .ruby-version
|
66
|
-
- .travis.yml
|
63
|
+
- ".document"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
67
|
- Gemfile
|
68
68
|
- Gemfile.lock
|
69
69
|
- LICENSE.txt
|
@@ -74,9 +74,8 @@ files:
|
|
74
74
|
- lib/rails-localization/controller.rb
|
75
75
|
- lib/rails-localization/engine.rb
|
76
76
|
- lib/rails-localization/i18n.rb
|
77
|
-
- lib/rails-localization/route_set.rb
|
78
77
|
- lib/rails-localization/router.rb
|
79
|
-
- lib/rails-localization/
|
78
|
+
- lib/rails-localization/url_helper.rb
|
80
79
|
- lib/rails_localization.rb
|
81
80
|
- rails-localization.gemspec
|
82
81
|
- test/i18n_integration_test.rb
|
@@ -133,17 +132,17 @@ require_paths:
|
|
133
132
|
- lib
|
134
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
135
134
|
requirements:
|
136
|
-
- -
|
135
|
+
- - ">="
|
137
136
|
- !ruby/object:Gem::Version
|
138
137
|
version: '0'
|
139
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
139
|
requirements:
|
141
|
-
- -
|
140
|
+
- - ">="
|
142
141
|
- !ruby/object:Gem::Version
|
143
142
|
version: '0'
|
144
143
|
requirements: []
|
145
144
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.7.7
|
147
146
|
signing_key:
|
148
147
|
specification_version: 4
|
149
148
|
summary: Rails localization Gem
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module RailsLocalization
|
2
|
-
module RouteSet
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
def url_for_with_locale(options = {})
|
6
|
-
url_for_without_locale RailsLocalization::UrlOptions.formatter(options)
|
7
|
-
end
|
8
|
-
alias_method_chain :url_for, :locale
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module RailsLocalization
|
2
|
-
module UrlOptions
|
3
|
-
def self.formatter opts
|
4
|
-
if opts[:_recall] && opts[:_recall].has_key?(:locale)
|
5
|
-
opts[:locale] = ::I18n.locale.to_s if opts[:locale].blank?
|
6
|
-
|
7
|
-
if !opts[:script_name].blank?
|
8
|
-
locale = opts.delete(:locale).to_s
|
9
|
-
affect_script_name(opts, locale) unless opts[:locale].to_s == ::I18n.default_locale.to_s
|
10
|
-
else
|
11
|
-
opts[:locale] = nil if opts[:locale].to_s == ::I18n.default_locale.to_s
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if opts.has_key?(:_positional_keys) && opts[:_positional_keys].first == :locale
|
16
|
-
i = opts[:_positional_keys].index(:locale)
|
17
|
-
opts[:_positional_args].insert i, (opts.delete(:locale) || ::I18n.locale.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
opts
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
|
25
|
-
def self.affect_script_name opts, locale
|
26
|
-
app_locales = ::I18n.locales[:main_app]
|
27
|
-
if opts[:script_name] =~ /^\/(#{::I18n.locales[:main_app].keys.join('|')})/
|
28
|
-
opts[:script_name].gsub!($1, locale)
|
29
|
-
else
|
30
|
-
opts[:script_name] = "/#{locale}#{opts[:script_name]}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|