Localizable routes with and without locale scoping

64 views
Skip to first unread message

Arnau Sanchez

unread,
Sep 15, 2011, 1:11:17 PM9/15/11
to I18n Routing
Hi,

After some time using translate_routes I am giving i18n_routing a try.
I'd like to get routes that look like this:

/route1
/route2
/es/ruta1
/es/ruta2

That's it, the default locale has no locale scope while all the others
language have (that's how translate_routes does it and I think it's
very pretty nice). So, with i18n_routing that's what I got so far
(trying to be DRY, repeating the routes is out of the question):

XYZ::Application.routes.draw do
localizable_routes = proc do
# routes here
end
localizable_routes.call

locales = (I18n.available_locales-[I18n.default_locale])
localized locales do
scope "/:i18n_locale", :constraints => {:i18n_locale =>
Regexp.new(locales.join('|')}) do
localizable_routes.call
end
end
end

Is there are better way or it's ok?

Arnau Sanchez

unread,
Sep 20, 2011, 9:53:33 AM9/20/11
to I18n Routing
Well, I still don't know whether it's a good way or not, but for the
moment I've DRYed it a little bit:

https://gist.github.com/1229107
Reply all
Reply to author
Forward
0 new messages