I have a rails 4.0.0 app running with friendly_id and globalize (even if freindly_id and globalize might not matter for this question).
Part of my routes.rb is:
scope "(:locale)", locale: /en|de/ do
resources :mainclasses, :path => :types
end
I now would like to have the ":path => :types" just for the english version (creating a url like www.website.com/types/etc, the german version should be ":path => :typen" (creating www.website.com/de/typen/etc).
Is there a way to change the path depending on the current locale?
I suggest you take a look at route_translator gem . It'll help you translate your routes to any locale, handle the locale with a scope or a subdomain, etc.
From your example, your would have something like this:
MyApp::Application.routes.draw do
localized do
resources :mainclasses, path: :types
end
end
Along with a locale file routes.yml
:
en:
routes:
types: types
de:
routes:
types: typen
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.