Created
July 16, 2009 16:07
-
-
Save javier/148504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RouteTranslation | |
mattr_accessor :translations | |
mattr_accessor :reverse_translations | |
rf=File.join(RAILS_ROOT,'config','route_translation.yml') | |
self.translations=YAML.load_file(rf) | |
self.reverse_translations=Hash.new | |
translations.keys.each do |key| | |
self.reverse_translations.merge! translations[key].invert | |
end | |
end | |
ActionController::Routing::RouteSet.class_eval do | |
def recognize_with_translation(request) | |
splitted_path=request.path.split('/') | |
first_segment = splitted_path[1] | |
if RouteTranslation.reverse_translations[first_segment] | |
splitted_path[1]=RouteTranslation.reverse_translations[first_segment] | |
translated_path=splitted_path.join('/') | |
env=request.instance_variable_get('@env') | |
env['REQUEST_URI']=translated_path | |
request.instance_variable_set '@env', env | |
request.instance_variable_set '@path', translated_path | |
end | |
recognize_without_translation(request) | |
end | |
alias_method_chain :recognize, :translation | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment