Created
May 3, 2011 22:23
-
-
Save Marchino/954394 to your computer and use it in GitHub Desktop.
How I made I18n_routing working with Devise. Couldn't translate routing scopes in any way, so I added a little workaround to the gem and...
This file contains hidden or 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
# I18n_routing/lib/I18n_routing_common.rb | |
# Return the correct translation for given values | |
def self.translation_for(name, type = :resources, option = nil) | |
# First, if an option is given, try to get the translation in the routes scope | |
if option | |
default = "{option}Noi18nRoutingTranslation" | |
t = I18n.t(option, :scope => "routes.#{name}.#{type}", :default => default) | |
return (t == default ? nil : t) | |
else | |
default = "{name}Noi18nRoutingTranslation" | |
# Try to get the translation in routes namescope first | |
t = I18n.t(:as, :scope => "routes.#{name}", :default => default) | |
t = I18n.t(name.to_s, :scope => type, :default => default) | |
return t if t and t != default | |
# this is what I added | |
t = I18n.t(name.to_s.gsub('/', '_'), :scope => type, :default => default) | |
return (t == default ? nil : t) | |
end | |
end |
This file contains hidden or 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
# config/en.yml | |
en: | |
named_routes_path: | |
users_new_registration: "users/registration" | |
users_edit_registration: "users/registration/edit" | |
# config/it.yml | |
it: | |
named_routes_path: | |
users_new_registration: "utenti/registrazione" | |
users_edit_registration: "utenti/registrazione/modifica" |
This file contains hidden or 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
# just an example, these are not all the routes needed :-) | |
devise_for :users, :skip => [:sessions, :registrations] do | |
get "users/new_registration" => "users/registrations#new", :as => "user_registration" | |
get "users/edit_registration" => "users/registrations#edit", :as => "edit_user_registration" | |
end |
PLease pack it as a pull request:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could pack it as a pull request to the gem! That would be awesome :)