chell
chell

Reputation: 7866

how to not show default locale in url for rails 3.0.11 app using translate_routes gem

I have a rails 3.0.11 application.

I am using the translate_routes gem which seems to have a bug so I can't do wildcard matches with locales as follows: routes.rb

MySite::Application.routes.draw do
.
.
.


match '/:locale/*path' => 'site#show', :as => 'cms'
 ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml')

end

SO I have had to add the following:

ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml') match '/(:locale)/*path' => 'cms#show', :as => 'cms', :locale => /fr|ar|en/

This works in so much as the paths have the locales and the system can find the routes. However it shows

en/somepage 

when I want

/

for the default.

Any ideas on how to not show the default locale?

Upvotes: 0

Views: 220

Answers (1)

ZogStriP
ZogStriP

Reputation: 567

Have you tried overwriting default_url_options like this?

def default_url_options(options={})
  options.merge!({ :locale => ((I18n.locale == I18n.default_locale) ? nil : I18n.locale) })
end

Upvotes: 1

Related Questions