i18n_routing 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ 0.4.4 (November 03, 2010)
2
+
3
+ * Fix bug with locale with a dash like pt-br
4
+
5
+ 0.4.3 (October 10, 2010)
6
+
7
+ * Named route can be translated by name or by path
8
+
1
9
  0.4.2 (September 20, 2010)
2
10
 
3
11
  * Fix a Rails3 bug, enabling again to do things like that: get :one, :two, :three
@@ -2,6 +2,10 @@
2
2
 
3
3
  # I18nRouting module for common usage methods
4
4
  module I18nRouting
5
+ def self.locale_escaped(locale)
6
+ locale.to_s.downcase.gsub('-', '_')
7
+ end
8
+
5
9
  # Return the correct translation for given values
6
10
  def self.translation_for(name, type = :resources, option = nil)
7
11
 
@@ -21,7 +21,7 @@ module ActionController
21
21
  def generation_requirements
22
22
  r = mkd_generation_requirements
23
23
  if @glang and !r.blank?
24
- r << " and I18n.locale.to_sym == :#{@glang}"
24
+ r << " and I18n.locale.to_sym == :'#{@glang}'"
25
25
  end
26
26
 
27
27
  return r
@@ -73,7 +73,7 @@ module ActionController
73
73
  alias_method :gl#{selector}, :#{selector}
74
74
 
75
75
  def #{selector}(*args)
76
- selector_g = '#{rlang}'.gsub('glang', I18n.locale.to_s).to_sym
76
+ selector_g = '#{rlang}'.gsub('glang', I18nRouting.locale_escaped(I18n.locale)).to_sym
77
77
 
78
78
  #logger.debug "Call routes : #{selector} => \#{selector_g} (#{rlang}) "
79
79
  #puts "Call routes : #{selector} => \#{selector_g} (#{rlang}) Found:\#{respond_to? selector_g and selector_g != :#{selector}}"
@@ -98,7 +98,7 @@ module ActionController
98
98
 
99
99
  @locales.each do |l|
100
100
  I18n.locale = l
101
- nt = "#{l}_#{name}"
101
+ nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
102
102
  t = I18nRouting.translation_for(name, :named_routes) || I18nRouting.translation_for(path, :named_routes_path)
103
103
  if nt != name and t
104
104
  gl_add_named_route(nt, t, options.merge(:glang => l))
@@ -169,9 +169,8 @@ module ActionController
169
169
  localized(nil) do
170
170
  locales.each do |l|
171
171
  I18n.locale = l
172
- nt = "#{l}_#{name}"
172
+ nt = "#{I18nRouting.locale_escaped(l)}_#{name}"
173
173
  if nt != name and (t = I18nRouting.translation_for(name, namespace))
174
- nt = "#{l}_#{name}"
175
174
  opts[:as] = t
176
175
  opts[:glang] = l
177
176
  opts[:controller] ||= name.to_s.pluralize
@@ -44,7 +44,7 @@ module I18nRouting
44
44
 
45
45
  resource = resource_from_params(type, r, opts.dup)
46
46
 
47
- res = ["#{locale}_#{r}".to_sym, opts]
47
+ res = ["#{I18nRouting.locale_escaped(locale)}_#{r}".to_sym, opts]
48
48
 
49
49
  constraints = opts[:constraints] ? opts[:constraints].dup : {}
50
50
  constraints[:i18n_locale] = locale.to_s
@@ -304,7 +304,7 @@ module I18nRouting
304
304
  # If a translated path exists, set localized infos
305
305
  if @localized_path and @localized_path != @path
306
306
  #@options[:controller] ||= @options[:as]
307
- @options[:as] = "#{locale}_#{@options[:as]}"
307
+ @options[:as] = "#{I18nRouting.locale_escaped(locale)}_#{@options[:as]}"
308
308
  @path = @localized_path
309
309
  @options[:constraints] = @options[:constraints] ? @options[:constraints].dup : {}
310
310
  @options[:constraints][:i18n_locale] = locale.to_s
@@ -348,7 +348,7 @@ module I18nRouting
348
348
  alias_method :localized_#{selector}, :#{selector}
349
349
 
350
350
  def #{selector}(*args)
351
- selector_g = '#{rlang}'.gsub('glang', I18n.locale.to_s).to_sym
351
+ selector_g = '#{rlang}'.gsub('glang', I18nRouting.locale_escaped(I18n.locale.to_s)).to_sym
352
352
 
353
353
  #puts "Call routes : #{selector} => \#{selector_g} (\#{I18n.locale}) "
354
354
  if respond_to? selector_g and selector_g != :#{selector}
@@ -325,6 +325,30 @@ describe :localized_routes do
325
325
 
326
326
  end
327
327
 
328
+ context 'locale with a dash (pt-br)' do
329
+
330
+ before do
331
+ I18n.locale = 'pt-BR'
332
+ end
333
+
334
+ it 'users resources' do
335
+ routes.send(:users_path).should == "/#{I18n.t :users, :scope => :'resources'}"
336
+ end
337
+
338
+ it "routes for the singleton resource alone should be translated correctly" do
339
+ routes.send(:foo_path).should == "/#{I18n.t :foo, :scope => :resource}"
340
+ end
341
+
342
+ it "named_route generates route using localized values" do
343
+ routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
344
+ end
345
+
346
+ it "custom translated path names" do
347
+ routes.send(:new_user_path).should == "/#{I18n.t :users, :scope => :resources}/#{I18n.t :new, :scope => :'path_names'}"
348
+ end
349
+
350
+ end
351
+
328
352
  # context "just output" do
329
353
  # it "output all routes properly" do
330
354
  # nested_routes.keys.collect(&:to_s).sort.each do |k|
@@ -0,0 +1,9 @@
1
+ pt-BR:
2
+ resources:
3
+ users: users-pt-br
4
+ resource:
5
+ foo: foo_fr-pt-br
6
+ named_routes_path:
7
+ about: 'a-propos-pt-br'
8
+ path_names:
9
+ new: 'nouveau-pt-br'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 3
9
- version: 0.4.3
8
+ - 4
9
+ version: 0.4.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guillaume Luccisano
@@ -14,14 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-11 00:00:00 -07:00
17
+ date: 2010-11-03 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: i18n
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
24
  requirements:
26
25
  - - ">"
27
26
  - !ruby/object:Gem::Version
@@ -48,6 +47,7 @@ files:
48
47
  - spec/i18n_routing/i18n_spec.rb
49
48
  - spec/locales/en.yml
50
49
  - spec/locales/fr.yml
50
+ - spec/locales/pt-br.yml
51
51
  - spec/spec_helper.rb
52
52
  - CHANGELOG.rdoc
53
53
  - MIT-LICENSE
@@ -64,7 +64,6 @@ rdoc_options: []
64
64
  require_paths:
65
65
  - lib
66
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
67
  requirements:
69
68
  - - ">="
70
69
  - !ruby/object:Gem::Version
@@ -72,7 +71,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
71
  - 0
73
72
  version: "0"
74
73
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
74
  requirements:
77
75
  - - ">="
78
76
  - !ruby/object:Gem::Version
@@ -84,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
82
  requirements: []
85
83
 
86
84
  rubyforge_project: i18n_routing
87
- rubygems_version: 1.3.7
85
+ rubygems_version: 1.3.6
88
86
  signing_key:
89
87
  specification_version: 3
90
88
  summary: I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !