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 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
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
3
+ - 1.9.3
4
+ - 2.0.0
5
+ bundler_args: --without=debug development
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 "test-unit"
9
- gem "test-spec"
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
- gem "simplecov", "~> 0.6.4", :platform => :ruby_19
15
- gem "rcov", "~> 1.0.0", :platform => :ruby_18
16
-
17
- gem "debugger", "~> 1.1.3", :platform => :ruby_19
18
- gem 'ruby-debug', :platform => :ruby_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 (3.2.8)
5
- actionpack (= 3.2.8)
6
- mail (~> 2.4.4)
7
- actionpack (3.2.8)
8
- activemodel (= 3.2.8)
9
- activesupport (= 3.2.8)
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
- journey (~> 1.0.4)
13
- rack (~> 1.4.0)
14
- rack-cache (~> 1.2)
15
- rack-test (~> 0.6.1)
16
- sprockets (~> 2.1.3)
17
- activemodel (3.2.8)
18
- activesupport (= 3.2.8)
19
- builder (~> 3.0.0)
20
- activerecord (3.2.8)
21
- activemodel (= 3.2.8)
22
- activesupport (= 3.2.8)
23
- arel (~> 3.0.2)
24
- tzinfo (~> 0.3.29)
25
- activeresource (3.2.8)
26
- activemodel (= 3.2.8)
27
- activesupport (= 3.2.8)
28
- activesupport (3.2.8)
29
- i18n (~> 0.6)
30
- multi_json (~> 1.0)
31
- addressable (2.3.2)
32
- arel (3.0.2)
33
- builder (3.0.0)
34
- capybara (1.1.2)
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
- selenium-webdriver (~> 2.0)
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.1.4)
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
- ffi (1.1.5)
53
- git (1.2.5)
54
- hike (1.2.1)
55
- i18n (0.6.1)
56
- jeweler (1.6.4)
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
- journey (1.0.4)
61
- json (1.7.5)
62
- libwebsocket (0.1.5)
63
- addressable
64
- linecache (0.46)
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.19)
73
- multi_json (1.3.6)
74
- nokogiri (1.5.5)
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.4.1)
77
- rack-cache (1.2)
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 (3.2.8)
84
- actionmailer (= 3.2.8)
85
- actionpack (= 3.2.8)
86
- activerecord (= 3.2.8)
87
- activeresource (= 3.2.8)
88
- activesupport (= 3.2.8)
89
- bundler (~> 1.0)
90
- railties (= 3.2.8)
91
- railties (3.2.8)
92
- actionpack (= 3.2.8)
93
- activesupport (= 3.2.8)
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
- rdoc (~> 3.4)
97
- thor (>= 0.14.6, < 2.0)
98
- rake (0.9.2.2)
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
- ruby-debug (0.10.4)
104
- columnize (>= 0.1)
105
- ruby-debug-base (~> 0.10.4.0)
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
- simplecov (0.6.4)
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
- test-spec (0.10.0)
129
- test-unit (2.5.2)
130
- thor (0.16.0)
131
- tilt (1.3.3)
132
- treetop (1.4.10)
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.33)
136
- xpath (0.1.4)
128
+ tzinfo (0.3.38)
129
+ xpath (2.0.0)
137
130
  nokogiri (~> 1.3)
138
- yard (0.6.8)
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.6.4)
148
- localization-middleware
149
- rails
150
- rcov (~> 1.0.0)
151
- ruby-debug
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 (~> 0.6.0)
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 to middleware
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
- # config/application.rb
25
- config.middleware.use "Rails::Localization::Middleware", %w(en ru)
29
+ get :users, :to => "users#index"
30
+ get "users/with_locale", :to => "users#with_locale"
31
+ get :welcome, :to => 'main#welcome'
26
32
 
27
- * And that's it. All existing urls now will be automatically localized, so there is no need to change anything,
28
- it just requires the translation for your I18n. If you want to define a locale for specific url, you can do it like that:
33
+ root :to => 'main#index'
34
+ end
29
35
 
30
- users_path(:locale => 'de')
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
- You can also predefine the default locale like I18n.default_locale = "de" in the initializers
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
- 0.2.0
1
+ 1.2.0
@@ -1,2 +1,26 @@
1
- require 'rails-localization/middleware'
2
- require 'rails-localization/routes_set_ext'
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