Created
December 5, 2011 16:11
-
-
Save sauberia/1434111 to your computer and use it in GitHub Desktop.
Manually creating localised routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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