我有一个使用 gem I18n_routing 的 Rails 网站。我有这样的路径:
domain.com/<place>/bookings
地方可能是“纽约”。我的目标是将路线翻译成这样:
domain.com/<place>/bokningar
我试图通过 I18n_routing 像这样翻译这个:
resources :places, :path => '', :except => [:index, :create, :new] do
#resources :flight_pages, :path => 'flyg', :only => [:show, :index]
#resources :hotel_pages, :path => 'hotell', :only => [:show, :index]
localized do
resources :bookings, :except => [:edit, :update] do
get :get_method_desc, :on => :collection
get :get_image_path, :on => :collection
end
end
get :autocomplete_place_name, :on => :collection
end
localized do
resources :places, :only => [:index, :create, :new]
end
使用这样的翻译文件:
resources:
places: 'plats'
bookings: 'bokningar'
我遇到了一个问题,如果我像上面那样,I18n_routing 无法识别“预订”需要翻译。
如果我更改设置以将本地化的操作置于整个资源之外:
localized do
resources :places, :path => '', :except => [:index, :create, :new] do
#resources :flight_pages, :path => 'flyg', :only => [:show, :index]
#resources :hotel_pages, :path => 'hotell', :only => [:show, :index]
resources :bookings, :except => [:edit, :update] do
get :get_method_desc, :on => :collection
get :get_image_path, :on => :collection
end
get :autocomplete_place_name, :on => :collection
end
end
localized do
resources :places, :only => [:index, :create, :new]
end
我翻译了空路径“地点”,因此路线变成:
domain.com/plats/<place>/bokningar
我试图places: ""
在翻译文件中设置,但 I18n_routing 只是跳过它。
我应该怎么做才能得到这样的翻译:
domain.com/<place>/bokningar (:se)
domain.com/<place>/bookings (:en)
即保持空路径并翻译嵌套资源“预订”?
编辑以回应 Aman Garg:我用于这些的路径是
new_place_booking_path(@place) #=> domain.com/<place>/bookings/new
place_bookings_path(@place) #=> domain.com/<place>/bookings