svenfuchs / routing-filter

routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
http://www.artweb-design.de
MIT License
464 stars 84 forks source link

Can't change locale in the URL? #39

Closed zackxu1 closed 12 years ago

zackxu1 commented 12 years ago

Hello.

I installed and set up routing-filter as described on the gem documentation page.

It works for the default locale. For example, if I set up my default locale as :en, the site is in English, and if I set my default locale as :zh, the site in Chinese.

But how can I make my site support BOTH languages? when the default locale is :zh, I tried to change the URL by changing the "zh" to "en" but the page is still in Chinese, not English.

Is this something not supported by this gem? If not, is there some other gem I can use? Or have I not set up the routing-filter gem properly?

Thanks! Zack

zackxu1 commented 12 years ago

After reading the source-code, I see what this gem is doing:

The Locale filter extracts segments matching /:locale from the beginning of the recognized path and exposes the page parameter as params[:locale]. When a path is generated the filter adds the segments to the path accordingly if the page parameter is passed to the url helper.

incoming url: /de/products filtered url: /products params: params[:locale] = 'de'

You can install the filter like this:

in config/routes.rb

Rails.application.routes.draw do filter :locale end

To make your named_route helpers or url_for add the locale segments you can use:

products_path(:locale => 'de') url_for(:products, :locale => 'de'))

I added the needed logic to application_controller.rb so it's all working.

As a suggestion, maybe you want to add the above to the gem documentation so it's more clear what this gem is doing for persisting locale. Thanks, this is a great gem! Zack