francesc / rails-translate-routes

MIT License
147 stars 50 forks source link

Namespaced translations stopped working after update to 0.1.x #26

Closed pshemek closed 12 years ago

pshemek commented 12 years ago

In my application (Rails 3.2.6, i18n 0.6.0):

config/routes.rb:

Centrum::Application.routes.draw do
  namespace :store do
    resources :products, :path => 'books'
    root :to => 'products#index'
  end
end

ActionDispatch::Routing::Translator.translate_from_file('config/routes.yml')

config/routes.yml:

pl:
  store: sklep
  books: ksiazki
  new: dodaj
  edit: edytuj

The controller is namespaced:

app/
  |- controllers/
    |- store/
      products_controller.rb

rake routes when on 0.0.5:

  store_products_pl GET        /sklep/ksiazki(.:format)                store/products#index {:locale=>"pl"}
                       POST       /sklep/ksiazki(.:format)                store/products#create {:locale=>"pl"}
  new_store_product_pl GET        /sklep/ksiazki/dodaj(.:format)          store/products#new {:locale=>"pl"}
 edit_store_product_pl GET        /sklep/ksiazki/:id/edytuj(.:format)     store/products#edit {:locale=>"pl"}
      store_product_pl GET        /sklep/ksiazki/:id(.:format)            store/products#show {:locale=>"pl"}
                       PUT        /sklep/ksiazki/:id(.:format)            store/products#update {:locale=>"pl"}
                       DELETE     /sklep/ksiazki/:id(.:format)            store/products#destroy {:locale=>"pl"}
         store_root_pl            /sklep(.:format)                        store/products#index {:locale=>"pl"}

rake routes when on 0.1.1:

     store_products_pl GET        /store/books(.:format)                  store/products#index {:locale=>"pl"}
                       POST       /store/books(.:format)                  store/products#create {:locale=>"pl"}
  new_store_product_pl GET        /store/books/new(.:format)              store/products#new {:locale=>"pl"}
 edit_store_product_pl GET        /store/books/:id/edit(.:format)         store/products#edit {:locale=>"pl"}
      store_product_pl GET        /store/books/:id(.:format)              store/products#show {:locale=>"pl"}
                       PUT        /store/books/:id(.:format)              store/products#update {:locale=>"pl"}
                       DELETE     /store/books/:id(.:format)              store/products#destroy {:locale=>"pl"}
         store_root_pl            /store(.:format)                        store/products#index {:locale=>"pl"}

Am I missing something in configuration or there is another reason?

francesc commented 12 years ago

Hey,

New version make some changes to routes.yml, now translations have to be scoped in order to avoid collisions with other translations from the app.

I updated the readme:

Important change from version 0.0.5 (Feb 2012) to 0.1.0 (June 2012): if you’re updating from an earlier version take into account that now translations defined in routes.yml are namespaced to avoid conflicts with other translations from app (thanks to cawel for the patch). To upgrade you just have to add the namespace ‘routes’ to your routes.yml (see example in the below docs).

So your routes.yml should be now:

pl:
  routes:
   store: sklep
   books: ksiazki
   new: dodaj
   edit: edytuj

Sorry for the inconvenience.

pshemek commented 12 years ago

It works, thank you.