i18n_routing 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.0 (September 13, 2011)
2
+
3
+ * Fixed a bug where i18n_routing was not restoring the default locale at boot (fishman)
4
+ * Handling of the rails3 alternative match syntax (toXXlc)
5
+
1
6
  0.4.7 (February 14, 2011)
2
7
 
3
8
  * Fix bug in empty translation handling
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
- gem "rails", '3.1.0rc4'
2
+ gem 'rails', '3.1.0'
3
3
  gem 'rspec', '>=2.5.0'
data/Gemfile.lock CHANGED
@@ -1,42 +1,41 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.1.0.rc4)
5
- actionpack (= 3.1.0.rc4)
4
+ actionmailer (3.1.0)
5
+ actionpack (= 3.1.0)
6
6
  mail (~> 2.3.0)
7
- actionpack (3.1.0.rc4)
8
- activemodel (= 3.1.0.rc4)
9
- activesupport (= 3.1.0.rc4)
7
+ actionpack (3.1.0)
8
+ activemodel (= 3.1.0)
9
+ activesupport (= 3.1.0)
10
10
  builder (~> 3.0.0)
11
11
  erubis (~> 2.7.0)
12
12
  i18n (~> 0.6)
13
- rack (~> 1.3.0)
14
- rack-cache (~> 1.0.1)
15
- rack-mount (~> 0.8.1)
16
- rack-test (~> 0.6.0)
17
- sprockets (~> 2.0.0.beta.10)
18
- tzinfo (~> 0.3.27)
19
- activemodel (3.1.0.rc4)
20
- activesupport (= 3.1.0.rc4)
21
- bcrypt-ruby (~> 2.1.4)
13
+ rack (~> 1.3.2)
14
+ rack-cache (~> 1.0.3)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.0)
18
+ activemodel (3.1.0)
19
+ activesupport (= 3.1.0)
20
+ bcrypt-ruby (~> 3.0.0)
22
21
  builder (~> 3.0.0)
23
22
  i18n (~> 0.6)
24
- activerecord (3.1.0.rc4)
25
- activemodel (= 3.1.0.rc4)
26
- activesupport (= 3.1.0.rc4)
27
- arel (~> 2.1.1)
28
- tzinfo (~> 0.3.27)
29
- activeresource (3.1.0.rc4)
30
- activemodel (= 3.1.0.rc4)
31
- activesupport (= 3.1.0.rc4)
32
- activesupport (3.1.0.rc4)
23
+ activerecord (3.1.0)
24
+ activemodel (= 3.1.0)
25
+ activesupport (= 3.1.0)
26
+ arel (~> 2.2.1)
27
+ tzinfo (~> 0.3.29)
28
+ activeresource (3.1.0)
29
+ activemodel (= 3.1.0)
30
+ activesupport (= 3.1.0)
31
+ activesupport (3.1.0)
33
32
  multi_json (~> 1.0)
34
- arel (2.1.3)
35
- bcrypt-ruby (2.1.4)
33
+ arel (2.2.1)
34
+ bcrypt-ruby (3.0.1)
36
35
  builder (3.0.0)
37
- diff-lcs (1.1.2)
36
+ diff-lcs (1.1.3)
38
37
  erubis (2.7.0)
39
- hike (1.1.0)
38
+ hike (1.2.1)
40
39
  i18n (0.6.0)
41
40
  mail (2.3.0)
42
41
  i18n (>= 0.4.0)
@@ -44,48 +43,49 @@ GEM
44
43
  treetop (~> 1.4.8)
45
44
  mime-types (1.16)
46
45
  multi_json (1.0.3)
47
- polyglot (0.3.1)
48
- rack (1.3.0)
49
- rack-cache (1.0.2)
46
+ polyglot (0.3.2)
47
+ rack (1.3.2)
48
+ rack-cache (1.0.3)
50
49
  rack (>= 0.4)
51
- rack-mount (0.8.1)
50
+ rack-mount (0.8.3)
52
51
  rack (>= 1.0.0)
53
52
  rack-ssl (1.3.2)
54
53
  rack
55
- rack-test (0.6.0)
54
+ rack-test (0.6.1)
56
55
  rack (>= 1.0)
57
- rails (3.1.0.rc4)
58
- actionmailer (= 3.1.0.rc4)
59
- actionpack (= 3.1.0.rc4)
60
- activerecord (= 3.1.0.rc4)
61
- activeresource (= 3.1.0.rc4)
62
- activesupport (= 3.1.0.rc4)
56
+ rails (3.1.0)
57
+ actionmailer (= 3.1.0)
58
+ actionpack (= 3.1.0)
59
+ activerecord (= 3.1.0)
60
+ activeresource (= 3.1.0)
61
+ activesupport (= 3.1.0)
63
62
  bundler (~> 1.0)
64
- railties (= 3.1.0.rc4)
65
- railties (3.1.0.rc4)
66
- actionpack (= 3.1.0.rc4)
67
- activesupport (= 3.1.0.rc4)
63
+ railties (= 3.1.0)
64
+ railties (3.1.0)
65
+ actionpack (= 3.1.0)
66
+ activesupport (= 3.1.0)
68
67
  rack-ssl (~> 1.3.2)
69
68
  rake (>= 0.8.7)
70
69
  rdoc (~> 3.4)
71
70
  thor (~> 0.14.6)
72
71
  rake (0.9.2)
73
- rdoc (3.8)
74
- rspec (2.5.0)
75
- rspec-core (~> 2.5.0)
76
- rspec-expectations (~> 2.5.0)
77
- rspec-mocks (~> 2.5.0)
78
- rspec-core (2.5.1)
79
- rspec-expectations (2.5.0)
72
+ rdoc (3.9.4)
73
+ rspec (2.6.0)
74
+ rspec-core (~> 2.6.0)
75
+ rspec-expectations (~> 2.6.0)
76
+ rspec-mocks (~> 2.6.0)
77
+ rspec-core (2.6.4)
78
+ rspec-expectations (2.6.0)
80
79
  diff-lcs (~> 1.1.2)
81
- rspec-mocks (2.5.0)
82
- sprockets (2.0.0.beta.10)
83
- hike (~> 1.0)
80
+ rspec-mocks (2.6.0)
81
+ sprockets (2.0.0)
82
+ hike (~> 1.2)
84
83
  rack (~> 1.0)
85
84
  tilt (~> 1.1, != 1.3.0)
86
85
  thor (0.14.6)
87
- tilt (1.3.2)
88
- treetop (1.4.9)
86
+ tilt (1.3.3)
87
+ treetop (1.4.10)
88
+ polyglot
89
89
  polyglot (>= 0.3.1)
90
90
  tzinfo (0.3.29)
91
91
 
@@ -93,5 +93,5 @@ PLATFORMS
93
93
  ruby
94
94
 
95
95
  DEPENDENCIES
96
- rails (= 3.1.0rc4)
96
+ rails (= 3.1.0)
97
97
  rspec (>= 2.5.0)
data/README.rdoc CHANGED
@@ -6,10 +6,9 @@ All necessary informations are available on the wiki: http://wiki.github.com/kwi
6
6
 
7
7
  For any question, use the i18_routing google group: http://groups.google.com/group/i18n-routing
8
8
 
9
- Works with Rails 2.3 and Rails 3.0
10
- => Rails3 beta and RC versions are no longer supported !
9
+ Works with Rails 2.3, 3.0 and 3.1
11
10
 
12
- == TODO for next releases (written the 9th of June)
11
+ == TODO for next releases (written the 9th of June 2010)
13
12
 
14
13
  * Handle multiple translations for same resources name (Example: nested and not nested resources)
15
14
  * Handle namespace translation (and path_prefix on Rails3)
@@ -28,5 +27,7 @@ Furthermore, if the i18n gem is present on your system, Rails will load it and s
28
27
  * fwalch
29
28
  * doubledrones: h13ronim (Marcin Michałowski)
30
29
  * rudionrails (Rudolf Schmidt)
30
+ * fishman (Reza Jelveh)
31
+ * toXXIc
31
32
 
32
- Copyright (c) 2010 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
33
+ Copyright (c) 2010-2011 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
@@ -91,6 +91,7 @@ module ActionController
91
91
  # Here, try to translate standard named routes
92
92
  name = name.to_s
93
93
 
94
+ stored_locale = I18n.locale
94
95
  @locales.each do |l|
95
96
  I18n.locale = l
96
97
  nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
@@ -100,6 +101,7 @@ module ActionController
100
101
  puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', name, l, t]) if @i18n_verbose
101
102
  end
102
103
  end
104
+ I18n.locale = stored_locale
103
105
 
104
106
  old_v = Thread.current[:globalized]
105
107
  Thread.current[:globalized] = true
@@ -160,6 +162,7 @@ module ActionController
160
162
 
161
163
  locales = @set.locales
162
164
  localized(nil) do
165
+ stored_locale = I18n.locale
163
166
  locales.each do |l|
164
167
  I18n.locale = l
165
168
  nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
@@ -180,6 +183,8 @@ module ActionController
180
183
  puts("[I18n] > localize %-10s: %40s (%s) => %s" % [namespace, nt, l, t]) if @set.i18n_verbose
181
184
  end
182
185
  end
186
+ I18n.locale = stored_locale
187
+
183
188
 
184
189
  if Thread.current[:i18n_nested_deep] < 2
185
190
  switch_no_named_localization(nil) do
@@ -31,6 +31,7 @@ module I18nRouting
31
31
  resource = resource_from_params(type, r, options.dup)
32
32
 
33
33
  # Check for translated resource
34
+ stored_locale = I18n.locale
34
35
  @locales.each do |locale|
35
36
  I18n.locale = locale
36
37
  localized_path = I18nRouting.translation_for(resource.name, type)
@@ -82,6 +83,7 @@ module I18nRouting
82
83
  localizable_route = resource
83
84
  end
84
85
  end
86
+ I18n.locale = stored_locale
85
87
  end
86
88
  return localizable_route
87
89
  end
@@ -182,24 +184,44 @@ module I18nRouting
182
184
  yield
183
185
  @skip_localization = old
184
186
  end
185
-
187
+
188
+
189
+
190
+ # Overrides match method
191
+ # Two variants of match are supported now
192
+ # match 'about' => 'pages#about', :as => 'about'
193
+ # match 'about', :to => 'pages#about'
194
+ # match 'home', :to => 'pages#home', :as => 'main' # Route name overridden to 'main'
186
195
  def match(*args)
187
196
  # Localize simple match only if there is no resource scope.
188
- if args.size == 1 and @locales and !parent_resource and args.last.is_a?(Hash) and args.first[:as]
189
- options = Marshal.load(Marshal.dump(args.first)) # Dump is dirty but how to make deep cloning easily ? :/
190
- path, to = options.find { |name, value| name.is_a?(String) }
191
- options.merge!(:to => to).delete(path)
192
- @locales.each do |locale|
193
- mapping = LocalizedMapping.new(locale, @set, @scope, path, options)
194
- if mapping.localizable?
195
- puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', args.first[:as], locale, mapping.path]) if @i18n_verbose
196
- @set.add_route(*mapping.to_route)
197
- end
197
+ if @locales and (args.size >= 1) and !parent_resource and
198
+ args.last.is_a?(Hash) # In both variants Hash should be present as last parameter
199
+
200
+ # Make deep copy of last argument (Hash)
201
+ options = Marshal.load(Marshal.dump(args.last)) # Dump is dirty but how to make deep cloning easily ? :/
202
+
203
+ # Now handle parameters
204
+ if (args.first.is_a?(Hash))
205
+ path, to = options.find { |name, value| name.is_a?(String) }
206
+ options.merge!(:to => to).delete(path)
207
+ else
208
+ path = args[0]
209
+ options[:as] ||= path
198
210
  end
199
-
200
- # Now, create the real match :
201
- return set_localizable_route(args.first[:as]) do
202
- super
211
+
212
+ if (options[:as])
213
+ @locales.each do |locale|
214
+ mapping = LocalizedMapping.new(locale, @set, @scope, path, options)
215
+ if mapping.localizable?
216
+ puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', options[:as], locale, mapping.path]) if @i18n_verbose
217
+ @set.add_route(*mapping.to_route)
218
+ end
219
+ end
220
+
221
+ # Now, create the real match :
222
+ return set_localizable_route(options[:as]) do
223
+ super
224
+ end
203
225
  end
204
226
  end
205
227
 
@@ -286,6 +308,7 @@ module I18nRouting
286
308
 
287
309
  def initialize(locale, set, scope, path, options)
288
310
  super(set, scope, path.clone, options ? options.clone : nil)
311
+ stored_locale = I18n.locale
289
312
 
290
313
  # try to get translated path :
291
314
  I18n.locale = locale
@@ -312,6 +335,7 @@ module I18nRouting
312
335
  else
313
336
  @localized_path = nil
314
337
  end
338
+ I18n.locale = stored_locale
315
339
  end
316
340
 
317
341
  # Return true if this route is localizable
@@ -65,12 +65,19 @@ describe :localized_routes do
65
65
  $r = ActionDispatch::Routing::RouteSet.new
66
66
  $r.draw do
67
67
  match 'not_about' => "not_about#show", :as => :not_about
68
+ match 'not_about2', :to => "not_about2#show"
69
+ match 'not_home', :to => 'not_pages#home', :as => 'not_main'
70
+
68
71
  resources :not_users
69
72
  resources :empty_resources
70
73
  resource :not_contact
71
74
 
72
75
  localized(I18n.available_locales, :verbose => true) do
73
76
  match 'about' => "about#show", :as => :about
77
+ match 'about2', :to => "about2#show"
78
+ match 'home', :to => 'pages#home', :as => 'main'
79
+
80
+
74
81
  match 'welcome/to/our/page' => "welcome#index", :as => :welcome
75
82
  match 'empty' => 'empty#show', :as => :empty
76
83
 
@@ -142,6 +149,12 @@ describe :localized_routes do
142
149
  routes.send(:not_about_path).should == "/not_about"
143
150
  end
144
151
 
152
+ if rails3?
153
+ it "of named_routes (another format)" do
154
+ routes.send(:not_about2_path).should == "/not_about2"
155
+ end
156
+ end
157
+
145
158
  it "of a singular resource" do
146
159
  routes.send(:not_contact_path).should == "/not_contact"
147
160
  end
@@ -160,6 +173,10 @@ describe :localized_routes do
160
173
 
161
174
  it "named_route uses default values" do
162
175
  routes.send(:about_path).should == "/about"
176
+ if rails3?
177
+ routes.send(:about2_path).should == "/about2"
178
+ routes.send(:main_path).should == "/home"
179
+ end
163
180
  routes.send(:welcome_path).should == '/welcome/to/our/page'
164
181
  end
165
182
 
@@ -217,8 +234,13 @@ describe :localized_routes do
217
234
 
218
235
  it "named_route generates route using localized values" do
219
236
  routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
237
+ if rails3?
238
+ routes.send(:about2_path).should == "/#{I18n.t :about2, :scope => :named_routes_path}"
239
+ routes.send(:main_path).should == "/#{I18n.t :home, :scope => :named_routes_path}"
240
+ end
220
241
  end
221
-
242
+
243
+
222
244
  it "named_route generated route from actual route name" do
223
245
  I18n.locale = :en
224
246
  routes.send(:welcome_path).should == "/#{I18n.t :welcome, :scope => :named_routes}"
@@ -242,9 +264,14 @@ describe :localized_routes do
242
264
  o = I18n.locale
243
265
  I18n.locale = "fr"
244
266
  routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
267
+ if rails3?
268
+ routes.send(:about2_path).should == "/#{I18n.t :about2, :scope => :named_routes_path}"
269
+ routes.send(:main_path).should == "/#{I18n.t :home, :scope => :named_routes_path}"
270
+ end
245
271
  I18n.locale = o
246
272
  end
247
273
 
274
+
248
275
  it "resource generates routes using localized values" do
249
276
  routes.send(:contact_path).should == "/#{I18n.t :contact, :scope => :resource}"
250
277
  end
@@ -256,6 +283,10 @@ describe :localized_routes do
256
283
  it "url_for generates routes using localized values" do
257
284
  url_for(:controller => :users).should == "/#{I18n.t :as, :scope => :'routes.users'}"
258
285
  url_for(:controller => :about, :action => :show).should == "/#{I18n.t :about, :scope => :named_routes_path}"
286
+ if rails3?
287
+ url_for(:controller => :about2, :action => :show).should == "/#{I18n.t :about2, :scope => :named_routes_path}"
288
+ url_for(:controller => :pages, :action => :home).should == "/#{I18n.t :home, :scope => :named_routes_path}"
289
+ end
259
290
  end
260
291
 
261
292
  if !rails3?
@@ -409,6 +440,10 @@ describe :localized_routes do
409
440
 
410
441
  it "named_route generates route using localized values" do
411
442
  routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
443
+ if rails3?
444
+ routes.send(:about2_path).should == "/#{I18n.t :about2, :scope => :named_routes_path}"
445
+ routes.send(:main_path).should == "/#{I18n.t :home, :scope => :named_routes_path}"
446
+ end
412
447
  end
413
448
 
414
449
  it "custom translated path names" do
data/spec/locales/en.yml CHANGED
@@ -11,5 +11,7 @@ en:
11
11
  contact: 'contact-us'
12
12
  named_routes_path:
13
13
  about: 'about-our-company'
14
+ about2: 'about-our-company2'
15
+ home: 'home'
14
16
  named_routes:
15
17
  welcome: 'welcome-to-our-page'
data/spec/locales/fr.yml CHANGED
@@ -33,6 +33,8 @@ fr:
33
33
  german: 'allemand'
34
34
  named_routes_path:
35
35
  about: 'a-propos'
36
+ about2: 'a-propos2'
37
+ home: 'accueil'
36
38
  'welcome/to/our/page': 'bienvenue/sur/notre/site' # no idea about french translation ;-) --R
37
39
  empty: ''
38
40
  sausage: 'saucisse'
@@ -5,5 +5,7 @@ pt-BR:
5
5
  foo: foo_fr-pt-br
6
6
  named_routes_path:
7
7
  about: 'a-propos-pt-br'
8
+ about2: 'a-propos-pt-br2'
9
+ home: 'casa'
8
10
  path_names:
9
11
  new: 'nouveau-pt-br'
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_routing
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease:
5
- version: 0.4.8
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Guillaume Luccisano
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-07-13 00:00:00 -07:00
18
+ date: 2011-09-13 00:00:00 -07:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,11 @@ dependencies:
21
26
  requirements:
22
27
  - - ">"
23
28
  - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 5
24
34
  version: 0.3.5
25
35
  type: :runtime
26
36
  version_requirements: *id001
@@ -64,17 +74,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
74
  requirements:
65
75
  - - ">="
66
76
  - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
67
80
  version: "0"
68
81
  required_rubygems_version: !ruby/object:Gem::Requirement
69
82
  none: false
70
83
  requirements:
71
84
  - - ">="
72
85
  - !ruby/object:Gem::Version
86
+ hash: 19
87
+ segments:
88
+ - 1
89
+ - 3
90
+ - 4
73
91
  version: 1.3.4
74
92
  requirements: []
75
93
 
76
94
  rubyforge_project: i18n_routing
77
- rubygems_version: 1.6.2
95
+ rubygems_version: 1.4.2
78
96
  signing_key:
79
97
  specification_version: 3
80
98
  summary: I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !