kwi / i18n_routing

I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !
MIT License
228 stars 48 forks source link

Named routes do not translate in Rails 2.3.8 #8

Closed activestylus closed 14 years ago

activestylus commented 14 years ago

All of my resources are translated with no problems.

However, the named_routes_path namespace gives me no results in my app.

Here is the freaky part though. When I go to script/console it works fine:

console > app.welcome_path
=> "/welcome" 
console > I18n.locale = 'es'
 => "es" 
console > app.welcome_path
 => "/bienvenido"

But if I call es_welcome_path in my app its undefined, and when I rake routes I dont see it anywhere (or any named route for that matter)

Here is a look inside config/locales/es.yml: es: named_routes_path: sidi: "sidi-8" sidi_info: "sidi-8-sobre-nosotros" sidi_contact: "sidi-8-contacto" sidi_thanks: "sidi-8-gracias" studio: "estudio-de-arquitectura" studio_contact: "estudio-de-arquitectura-contacto" studio_thanks: "estudio-de-arquitectura-gracias" studio_team: "estudio-de-arquitectura-equipo" tech: "tecnicas-de-rehabilitacion" tech_contact: "tecnicas-de-rehabilitacion-contacto" tech_thanks: "tecnicas-de-rehabilitacion-gracias" tech_team: "tecnicas-de-rehabilitacion-equipo" welcome: "bienvenido"

Here is how I'm setting the locale in application_controller:

before_filter :set_current_locale
private
def set_current_locale
  I18n.locale = params[:locale] ? params[:locale] : :en
end

Any idea why named routes are being ignored by this gem?

FWIW I'm running on 1.8.7-head via RVM

activestylus commented 14 years ago

Ok I just tried this on a fresh 2.3.8 app and it worked, so there must be something in my own code that's conflicting.

kwi commented 14 years ago

Hi,

Sorry for the delay, but glad you find it yourself !

activestylus commented 14 years ago

For speed's sake I ended up using translate_routes:

http://github.com/raul/translate_routes

It was a faster drop-in that just worked right away. I just needed to add one line to my routes.rb and it was good to go.

Some feedback for you based on my experience with both:

  1. I liked how I didn't need to establish any namespaces in my locale files. The plugin just did a simple I18n lookup to whatever was available. This allows me to re-use translations, instead of having to repeat them in a path namespace. In the event that I need special formatting (something-like-this), all I need to do is specify a separate routes yaml file and the plugin takes care of the rest.
  2. routes.rb setup was a simple one-liner specifying where the locale file was: ActionController::Routing::Translator.translate_from_file 'config', 'locales', 'routes.yml'
  3. It also did something pretty cool, the current locale urls were listed as normal

    /users/new

but anything aside from current would automatically get a namespace

/es/usuarios/nuevo
/de/benutzer/neue

All of this with zero configuration, which I thought was pretty nice.

The only downside to this is the fact that it's a plugin (gems are better) and the code hasn't been touched in over a year, which means Rails 3 support is probably not on the horizon.

I definitely plan on using your gem for my Rails 3 apps, and hope that you take notes on my feedback.

Thanks for sharing this gem btw - keep up the good work!

kwi commented 14 years ago

Great, I'm glad you finally get this stuff working event if it was withtout i18n_routing ! And yes, translate_routes does work with Rails3 and I'm not sure I like the way it add automatic namespace.

But thanks for the advice :)