Permalink
Browse files

add routing_locale/routing_locale_helper.rb in lib

  • Loading branch information...
1 parent 643c287 commit be49f2555b0f0be6a573ef3e16f35716c77d0707 @dre3k committed Jan 16, 2011
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/routing_locale/routing_locale_helper.rb
@@ -0,0 +1,23 @@
+module RoutingLocaleHelper
+ POSTFIXES = %w[_path _url]
+
+ EXPLICIT_LOCALE_ROUTES = Rails.application.routes.routes.
+ reject{|r| (r.path =~ %r[/rails/info/properties]) || r.name.nil?}.
+ map{|r| r.name.to_s}.reject{|r| r !~ /locale_/}
+
+ IMPLICIT_LOCALE_ROUTES = EXPLICIT_LOCALE_ROUTES.map{|r| r.sub('locale_', '')}
+
+ def self.included(base)
+ base.instance_eval do
+ POSTFIXES.each do |postfix|
+ EXPLICIT_LOCALE_ROUTES.each_with_index do |explicit_route, i|
+ implicit_route = IMPLICIT_LOCALE_ROUTES[i]
+
+ define_method (implicit_route + postfix).to_sym do |*args|
+ send (explicit_route + postfix).to_sym, params[:locale], *args
+ end
+ end
+ end
+ end
+ end
+end

0 comments on commit be49f25

Please sign in to comment.