Skip to content

Instantly share code, notes, and snippets.

@Marchino
Created May 3, 2011 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Marchino/954394 to your computer and use it in GitHub Desktop.
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...
# 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
# 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"
# 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
@albertbellonch
Copy link

You could pack it as a pull request to the gem! That would be awesome :)

@cis-deepesh
Copy link

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