Skip to content

Instantly share code, notes, and snippets.

@sauberia
Created December 5, 2011 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauberia/1434111 to your computer and use it in GitHub Desktop.
Save sauberia/1434111 to your computer and use it in GitHub Desktop.
Manually creating localised routes
Example::Application.routes.draw do
REGEX_ID = /[1-9]\d*/
REGEX_COUNTRY_SLUG = /[a-zà-ÿ\-]+/
REGEX_SLUG = /[a-zà-ÿ\d\-]+/
REGEX_LOCALE = /#{I18n.available_locales.join('|')}/
def t_route name, locale
I18n.t("named_routes.#{name}", :locale => locale)
end
I18n.available_locales.each do |l|
scope "/#{l}", :locale => l.to_s do
match t_route('article', l) => 'articles#show', :as => "#{l}_article", :country_slug => REGEX_COUNTRY_SLUG, :page => REGEX_ID
match t_route('articles', l) => 'articles#index', :as => "#{l}_articles", :country_slug => REGEX_COUNTRY_SLUG, :page => REGEX_ID
scope '/:country_slug', :country_slug => REGEX_COUNTRY_SLUG do
match t_route('country_services', l) => 'country_services#index', :as => "#{l}_country_services"
match t_route('country_service', l) => 'country_services#show', :as => "#{l}_country_service", :service_slug => REGEX_SLUG
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment