rails-localization 0.2.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -3
- data/Gemfile +20 -13
- data/Gemfile.lock +113 -122
- data/README.rdoc +62 -7
- data/VERSION +1 -1
- data/lib/rails-localization.rb +26 -2
- data/lib/rails-localization/controller.rb +22 -0
- data/lib/rails-localization/engine.rb +6 -0
- data/lib/rails-localization/i18n.rb +9 -0
- data/lib/rails-localization/route_set.rb +12 -0
- data/lib/rails-localization/router.rb +15 -0
- data/lib/rails-localization/url_options.rb +34 -0
- data/rails-localization.gemspec +25 -44
- data/test/i18n_integration_test.rb +28 -0
- data/test/mapper_integration_test.rb +45 -0
- data/test/rails-localization_test.rb +47 -47
- data/test/support/capybara_helper.rb +9 -5
- data/test/test_app/Gemfile +4 -0
- data/test/test_app/Gemfile.lock +93 -0
- data/test/test_app/Rakefile +7 -0
- data/test/test_app/app/controllers/users_controller.rb +1 -1
- data/test/test_app/config/application.rb +1 -4
- data/test/test_app/config/environments/development.rb +3 -3
- data/test/test_app/config/environments/production.rb +2 -0
- data/test/test_app/config/environments/test.rb +2 -3
- data/test/test_app/config/routes.rb +10 -7
- data/test/test_helper.rb +3 -8
- data/test/urls_overwriting_test.rb +9 -17
- metadata +34 -130
- data/.rvmrc +0 -1
- data/lib/rails-localization/middleware.rb +0 -8
- data/lib/rails-localization/routes_set_ext.rb +0 -61
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45f814e963b1625936bd65aadc83e4096acdca74
|
4
|
+
data.tar.gz: dee12c7e218988db2e34be091454a175199002d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5be965913a0177a17b5f9739cf744a258b7e6e842fdf9fb05de55029ce72eb0855e4688840e00a959e7a8f8fea2f76954062ca67068b9d56fb1d453fd98f5efa
|
7
|
+
data.tar.gz: 50e6d35007d78709384bc562a52d299157a7cd302d4f74bf1f3a640d3874b3b35ceddbd4a81ea5d43ff6e3bee665eb541d89babd6ae5fe07b15caeac4f7ba7f8
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails-localization
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem "rails"
|
4
|
-
gem "localization-middleware"
|
3
|
+
gem "rails", ">= 4.0.0"
|
5
4
|
gem "i18n"
|
6
5
|
|
6
|
+
group :debug do
|
7
|
+
gem "byebug", platform: :ruby_20
|
8
|
+
#gem "debugger", "~> 1.2.2", platform: :ruby_19
|
9
|
+
#gem "ruby-debug", platform: :ruby_18
|
10
|
+
end
|
11
|
+
|
7
12
|
group :development, :test do
|
8
|
-
gem "
|
9
|
-
|
10
|
-
gem "shoulda"
|
11
|
-
gem "yard", "~> 0.6.0"
|
12
|
-
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "jeweler", "~> 1.8.0"
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
gem "
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
group :debug, :test do
|
17
|
+
gem "yard"
|
18
|
+
gem "redcarpet"
|
19
|
+
end
|
20
|
+
|
21
|
+
group :test do
|
22
|
+
gem 'minitest'
|
23
|
+
gem "test-unit"
|
24
|
+
gem 'shoulda-context'
|
25
|
+
gem 'shoulda-matchers'
|
19
26
|
|
20
27
|
gem "capybara"
|
21
|
-
end
|
28
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,156 +1,147 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (
|
5
|
-
actionpack (=
|
6
|
-
mail (~> 2.
|
7
|
-
actionpack (
|
8
|
-
|
9
|
-
|
10
|
-
builder (~> 3.0.0)
|
4
|
+
actionmailer (4.0.2)
|
5
|
+
actionpack (= 4.0.2)
|
6
|
+
mail (~> 2.5.4)
|
7
|
+
actionpack (4.0.2)
|
8
|
+
activesupport (= 4.0.2)
|
9
|
+
builder (~> 3.1.0)
|
11
10
|
erubis (~> 2.7.0)
|
12
|
-
|
13
|
-
rack (~>
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
11
|
+
rack (~> 1.5.2)
|
12
|
+
rack-test (~> 0.6.2)
|
13
|
+
activemodel (4.0.2)
|
14
|
+
activesupport (= 4.0.2)
|
15
|
+
builder (~> 3.1.0)
|
16
|
+
activerecord (4.0.2)
|
17
|
+
activemodel (= 4.0.2)
|
18
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
19
|
+
activesupport (= 4.0.2)
|
20
|
+
arel (~> 4.0.0)
|
21
|
+
activerecord-deprecated_finders (1.0.3)
|
22
|
+
activesupport (4.0.2)
|
23
|
+
i18n (~> 0.6, >= 0.6.4)
|
24
|
+
minitest (~> 4.2)
|
25
|
+
multi_json (~> 1.3)
|
26
|
+
thread_safe (~> 0.1)
|
27
|
+
tzinfo (~> 0.3.37)
|
28
|
+
addressable (2.3.5)
|
29
|
+
arel (4.0.1)
|
30
|
+
atomic (1.1.14)
|
31
|
+
builder (3.1.4)
|
32
|
+
byebug (2.5.0)
|
33
|
+
columnize (~> 0.3.6)
|
34
|
+
debugger-linecache (~> 1.2.0)
|
35
|
+
capybara (2.2.0)
|
35
36
|
mime-types (>= 1.16)
|
36
37
|
nokogiri (>= 1.3.3)
|
37
38
|
rack (>= 1.0.0)
|
38
39
|
rack-test (>= 0.5.4)
|
39
|
-
|
40
|
-
xpath (~> 0.1.4)
|
41
|
-
childprocess (0.3.5)
|
42
|
-
ffi (~> 1.0, >= 1.0.6)
|
40
|
+
xpath (~> 2.0)
|
43
41
|
columnize (0.3.6)
|
44
|
-
debugger (1.
|
45
|
-
columnize (>= 0.3.1)
|
46
|
-
debugger-linecache (~> 1.1.1)
|
47
|
-
debugger-ruby_core_source (~> 1.1.3)
|
48
|
-
debugger-linecache (1.1.2)
|
49
|
-
debugger-ruby_core_source (>= 1.1.1)
|
50
|
-
debugger-ruby_core_source (1.1.3)
|
42
|
+
debugger-linecache (1.2.0)
|
51
43
|
erubis (2.7.0)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
faraday (0.8.8)
|
45
|
+
multipart-post (~> 1.2.0)
|
46
|
+
git (1.2.6)
|
47
|
+
github_api (0.10.1)
|
48
|
+
addressable
|
49
|
+
faraday (~> 0.8.1)
|
50
|
+
hashie (>= 1.2)
|
51
|
+
multi_json (~> 1.4)
|
52
|
+
nokogiri (~> 1.5.2)
|
53
|
+
oauth2
|
54
|
+
hashie (2.0.5)
|
55
|
+
highline (1.6.20)
|
56
|
+
hike (1.2.3)
|
57
|
+
httpauth (0.2.0)
|
58
|
+
i18n (0.6.9)
|
59
|
+
jeweler (1.8.8)
|
60
|
+
builder
|
57
61
|
bundler (~> 1.0)
|
58
62
|
git (>= 1.2.5)
|
63
|
+
github_api (= 0.10.1)
|
64
|
+
highline (>= 1.6.15)
|
65
|
+
nokogiri (= 1.5.10)
|
59
66
|
rake
|
60
|
-
|
61
|
-
json (1.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
rbx-require-relative (> 0.0.4)
|
66
|
-
localization-middleware (0.1.0)
|
67
|
-
i18n
|
68
|
-
mail (2.4.4)
|
69
|
-
i18n (>= 0.4.0)
|
67
|
+
rdoc
|
68
|
+
json (1.8.1)
|
69
|
+
jwt (0.1.8)
|
70
|
+
multi_json (>= 1.5)
|
71
|
+
mail (2.5.4)
|
70
72
|
mime-types (~> 1.16)
|
71
73
|
treetop (~> 1.4.8)
|
72
|
-
mime-types (1.
|
73
|
-
|
74
|
-
|
74
|
+
mime-types (1.25.1)
|
75
|
+
minitest (4.7.5)
|
76
|
+
multi_json (1.8.2)
|
77
|
+
multi_xml (0.5.5)
|
78
|
+
multipart-post (1.2.0)
|
79
|
+
nokogiri (1.5.10)
|
80
|
+
oauth2 (0.9.2)
|
81
|
+
faraday (~> 0.8)
|
82
|
+
httpauth (~> 0.2)
|
83
|
+
jwt (~> 0.1.4)
|
84
|
+
multi_json (~> 1.0)
|
85
|
+
multi_xml (~> 0.5)
|
86
|
+
rack (~> 1.2)
|
75
87
|
polyglot (0.3.3)
|
76
|
-
rack (1.
|
77
|
-
rack-
|
78
|
-
rack (>= 0.4)
|
79
|
-
rack-ssl (1.3.2)
|
80
|
-
rack
|
81
|
-
rack-test (0.6.1)
|
88
|
+
rack (1.5.2)
|
89
|
+
rack-test (0.6.2)
|
82
90
|
rack (>= 1.0)
|
83
|
-
rails (
|
84
|
-
actionmailer (=
|
85
|
-
actionpack (=
|
86
|
-
activerecord (=
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
railties (
|
92
|
-
actionpack (=
|
93
|
-
activesupport (=
|
94
|
-
rack-ssl (~> 1.3.2)
|
91
|
+
rails (4.0.2)
|
92
|
+
actionmailer (= 4.0.2)
|
93
|
+
actionpack (= 4.0.2)
|
94
|
+
activerecord (= 4.0.2)
|
95
|
+
activesupport (= 4.0.2)
|
96
|
+
bundler (>= 1.3.0, < 2.0)
|
97
|
+
railties (= 4.0.2)
|
98
|
+
sprockets-rails (~> 2.0.0)
|
99
|
+
railties (4.0.2)
|
100
|
+
actionpack (= 4.0.2)
|
101
|
+
activesupport (= 4.0.2)
|
95
102
|
rake (>= 0.8.7)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
rbx-require-relative (0.0.9)
|
100
|
-
rcov (1.0.0)
|
101
|
-
rdoc (3.12)
|
103
|
+
thor (>= 0.18.1, < 2.0)
|
104
|
+
rake (10.1.0)
|
105
|
+
rdoc (4.0.1)
|
102
106
|
json (~> 1.4)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
ruby-debug-base (0.10.4)
|
107
|
-
linecache (>= 0.3)
|
108
|
-
rubyzip (0.9.9)
|
109
|
-
selenium-webdriver (2.25.0)
|
110
|
-
childprocess (>= 0.2.5)
|
111
|
-
libwebsocket (~> 0.1.3)
|
112
|
-
multi_json (~> 1.0)
|
113
|
-
rubyzip
|
114
|
-
shoulda (3.1.1)
|
115
|
-
shoulda-context (~> 1.0)
|
116
|
-
shoulda-matchers (~> 1.2)
|
117
|
-
shoulda-context (1.0.0)
|
118
|
-
shoulda-matchers (1.3.0)
|
107
|
+
redcarpet (3.0.0)
|
108
|
+
shoulda-context (1.1.6)
|
109
|
+
shoulda-matchers (2.4.0)
|
119
110
|
activesupport (>= 3.0.0)
|
120
|
-
|
121
|
-
multi_json (~> 1.0)
|
122
|
-
simplecov-html (~> 0.5.3)
|
123
|
-
simplecov-html (0.5.3)
|
124
|
-
sprockets (2.1.3)
|
111
|
+
sprockets (2.10.1)
|
125
112
|
hike (~> 1.2)
|
113
|
+
multi_json (~> 1.0)
|
126
114
|
rack (~> 1.0)
|
127
115
|
tilt (~> 1.1, != 1.3.0)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
116
|
+
sprockets-rails (2.0.1)
|
117
|
+
actionpack (>= 3.0)
|
118
|
+
activesupport (>= 3.0)
|
119
|
+
sprockets (~> 2.8)
|
120
|
+
test-unit (2.5.5)
|
121
|
+
thor (0.18.1)
|
122
|
+
thread_safe (0.1.3)
|
123
|
+
atomic
|
124
|
+
tilt (1.4.1)
|
125
|
+
treetop (1.4.15)
|
133
126
|
polyglot
|
134
127
|
polyglot (>= 0.3.1)
|
135
|
-
tzinfo (0.3.
|
136
|
-
xpath (0.
|
128
|
+
tzinfo (0.3.38)
|
129
|
+
xpath (2.0.0)
|
137
130
|
nokogiri (~> 1.3)
|
138
|
-
yard (0.
|
131
|
+
yard (0.8.7.3)
|
139
132
|
|
140
133
|
PLATFORMS
|
141
134
|
ruby
|
142
135
|
|
143
136
|
DEPENDENCIES
|
137
|
+
byebug
|
144
138
|
capybara
|
145
|
-
debugger (~> 1.1.3)
|
146
139
|
i18n
|
147
|
-
jeweler (~> 1.
|
148
|
-
|
149
|
-
rails
|
150
|
-
|
151
|
-
|
152
|
-
shoulda
|
153
|
-
simplecov (~> 0.6.4)
|
154
|
-
test-spec
|
140
|
+
jeweler (~> 1.8.0)
|
141
|
+
minitest
|
142
|
+
rails (>= 4.0.0)
|
143
|
+
redcarpet
|
144
|
+
shoulda-context
|
145
|
+
shoulda-matchers
|
155
146
|
test-unit
|
156
|
-
yard
|
147
|
+
yard
|
data/README.rdoc
CHANGED
@@ -19,17 +19,72 @@ The gem that allows to localize your Rails app through the Rack middleware in a
|
|
19
19
|
|
20
20
|
gem install rails-localization
|
21
21
|
|
22
|
-
* Now it should be added
|
22
|
+
* Now it should be added into routes
|
23
|
+
|
24
|
+
# config/routes.rb
|
25
|
+
TestApp::Application.routes.draw do
|
26
|
+
localized({"en" => "English", "ru" => "Russian"}) do
|
27
|
+
mount SubApp::Engine => '/sub', :as => :sub_app_engine
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
get :users, :to => "users#index"
|
30
|
+
get "users/with_locale", :to => "users#with_locale"
|
31
|
+
get :welcome, :to => 'main#welcome'
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
root :to => 'main#index'
|
34
|
+
end
|
29
35
|
|
30
|
-
|
36
|
+
get "users/without_locale", :to => "users#without_locale"
|
37
|
+
get "users/with_defined_locale", :to => "users#with_defined_locale", locale: "en"
|
38
|
+
end
|
31
39
|
|
32
|
-
|
40
|
+
And that whould generate you something like that
|
41
|
+
|
42
|
+
$ rake routes
|
43
|
+
sub_app_engine (/:locale)/sub SubApp::Engine {:locale=>/en|ru/}
|
44
|
+
users GET (/:locale)/users(.:format) users#index {:locale=>/en|ru/}
|
45
|
+
users_with_locale GET (/:locale)/users/with_locale(.:format) users#with_locale {:locale=>/en|ru/}
|
46
|
+
welcome GET (/:locale)/welcome(.:format) main#welcome {:locale=>/en|ru/}
|
47
|
+
root /(:locale)(.:format) main#index {:locale=>/en|ru/}
|
48
|
+
users_without_locale GET /users/without_locale(.:format) users#without_locale
|
49
|
+
users_with_defined_locale GET /users/with_defined_locale(.:format) users#with_defined_locale {:locale=>"en"}
|
50
|
+
|
51
|
+
Routes for SubApp::Engine {:locale=>/en|ru/}:
|
52
|
+
print_redirect GET /print_redirect(.:format) sub_app/main#print_redirect
|
53
|
+
welcome GET /welcome(.:format) sub_app/main#welcome
|
54
|
+
root / sub_app/main#index
|
55
|
+
|
56
|
+
* Inside your application you can use it like that
|
57
|
+
|
58
|
+
TestApp::Application.routes.url_helpers.users_path # => /users
|
59
|
+
TestApp::Application.routes.url_helpers.users_path(:locale => "ru") # => /ru/users
|
60
|
+
|
61
|
+
And that should also take into account the fact that you switched `I18n.locale`
|
62
|
+
|
63
|
+
I18n.locale = :ru
|
64
|
+
TestApp::Application.routes.url_helpers.users_path # => /ru/users
|
65
|
+
|
66
|
+
So, the logic is **when ever current locale doesn't match default one, it is added url**
|
67
|
+
|
68
|
+
* Engines
|
69
|
+
|
70
|
+
So, you can also localize an application, that will be mounted later on onto another one.
|
71
|
+
|
72
|
+
SubApp::Engine.routes.draw do
|
73
|
+
localized({"en" => "English", "ru" => "Russian"}) do
|
74
|
+
get :print_redirect, :to => 'main#print_redirect'
|
75
|
+
get :welcome, :to => 'main#welcome'
|
76
|
+
root :to => 'main#index'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
* Accessing locales
|
81
|
+
|
82
|
+
An easy thing
|
83
|
+
|
84
|
+
I18n.locales[:main_app] # => {"en" => "English", "ru" => "Russian"}
|
85
|
+
I18n.locales[:sub_app] # => {"en" => "English", "ru" => "Russian"}
|
86
|
+
|
87
|
+
**NB!** You can also predefine the default locale like `I18n.default_locale = "de"` in the initializers
|
33
88
|
|
34
89
|
== Contributing to rails-localization
|
35
90
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.2.0
|
data/lib/rails-localization.rb
CHANGED
@@ -1,2 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module RailsLocalization
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'rails-localization/engine'
|
5
|
+
|
6
|
+
if defined?(ActiveSupport)
|
7
|
+
require 'rails-localization/i18n'
|
8
|
+
require 'rails-localization/url_options'
|
9
|
+
|
10
|
+
I18n.extend RailsLocalization::I18n
|
11
|
+
|
12
|
+
ActiveSupport.on_load(:before_configuration) do
|
13
|
+
require 'rails-localization/router'
|
14
|
+
require 'rails-localization/route_set'
|
15
|
+
|
16
|
+
ActionDispatch::Routing::RouteSet.send :include, RailsLocalization::RouteSet
|
17
|
+
ActionDispatch::Routing::Mapper.send :include, ActionDispatch::Routing::Mapper::Localization
|
18
|
+
|
19
|
+
ActiveSupport.on_load(:action_controller) do
|
20
|
+
require 'rails-localization/controller'
|
21
|
+
ActionController::Base.send :include, RailsLocalization::Controller
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
warn "ActiveSupport is not defined. Ignoring RailsLocalization loading"
|
26
|
+
end
|