2016-08-16 49 views
0

所以我給了gem route_translator一個鏡頭。 簡單的原因是我需要它來翻譯我在FR和NL中的一些路線。Rails 4 with gem route_translator生成太多路由

它工作得很好......有點「太好」我會說。

route_translator應該考慮到我的2個區域設置文件fr.yml和nl.yml

如DOC解釋這裏https://github.com/enriclluelles/route_translator,我包我想與翻譯的路線:

localized do 
... 
end 

這是我的路線:

scope '(:locale)', constraints: { locale: /nl|fr/ } do 
    devise_for :users 

    resources :articles, :path => 'newsfeed', only: [:index, :edit, :destroy, :update, :new, :create] 

    localized do 
    get 'pages/clients', as: :clients 
    get 'pages/employes', as: :employes 
    end 

    root to: 'languages#select' 

    get '*path' => redirect('/') 
end 

我YMLs文件是:

對於fr.yml

fr: 
    routes: 
    clients: "clients" 
    employees: "employes" 

對於nl.yml

nl: 
    routes: 
    clients: "klanten" 
    employees: "personeel" 

作爲一個結果我得到每翻譯,而不是僅僅2(FR和NL)52條新航線。

clients_en GET /en(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"en"} 
clients_ar GET /ar(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ar"} 
clients_az GET /az(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"az"} 
clients_bg GET /bg(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"bg"} 
clients_bn GET /bn(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"bn"} 
clients_bs GET /bs(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"bs"} 
clients_ca GET /ca(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ca"} 
clients_cs GET /cs(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"cs"} 
clients_da GET /da(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"da"} 
clients_de_ch GET /de-ch(/:locale)/pages/clients(.:format) pages#clients {:locale=>"de-CH"} 
clients_de GET /de(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"de"} 
clients_el GET /el(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"el"} 
clients_en_gb GET /en-gb(/:locale)/pages/clients(.:format) pages#clients {:locale=>"en-GB"} 
clients_es_mx GET /es-mx(/:locale)/pages/clients(.:format) pages#clients {:locale=>"es-MX"} 
clients_es GET /es(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"es"} 
clients_et GET /et(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"et"} 
clients_fa GET /fa(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"fa"} 
clients_fi GET /fi(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"fi"} 
clients_fr_ca GET /fr-ca(/:locale)/pages/clients(.:format) pages#clients {:locale=>"fr-CA"} 
clients_he GET /he(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"he"} 
clients_hr GET /hr(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"hr"} 
clients_hu GET /hu(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"hu"} 
clients_id GET /id(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"id"} 
clients_is GET /is(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"is"} 
clients_it GET /it(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"it"} 
clients_ja GET /ja(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ja"} 
clients_ko GET /ko(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ko"} 
clients_lt GET /lt(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"lt"} 
clients_lv GET /lv(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"lv"} 
clients_my GET /my(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"my"} 
clients_nb GET /nb(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"nb"} 
clients_nl GET /nl(/:locale)/pages/klanten(.:format)  pages#clients {:locale=>"nl"} 
clients_nn_no GET /nn-no(/:locale)/pages/clients(.:format) pages#clients {:locale=>"nn-NO"} 
clients_no GET /no(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"no"} 
clients_pl GET /pl(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"pl"} 
clients_pt_br GET /pt-br(/:locale)/pages/clients(.:format) pages#clients {:locale=>"pt-BR"} 
clients_pt GET /pt(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"pt"} 
clients_ro GET /ro(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ro"} 
clients_ru GET /ru(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"ru"} 
clients_sk GET /sk(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"sk"} 
clients_sl GET /sl(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"sl"} 
clients_sr_rs GET /sr-rs(/:locale)/pages/clients(.:format) pages#clients {:locale=>"sr-RS"} 
clients_sr GET /sr(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"sr"} 
clients_sv GET /sv(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"sv"} 
clients_th GET /th(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"th"} 
clients_tr GET /tr(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"tr"} 
clients_uk GET /uk(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"uk"} 
clients_vi GET /vi(/:locale)/pages/clients(.:format)  pages#clients {:locale=>"vi"} 
clients_zh_cn GET /zh-cn(/:locale)/pages/clients(.:format) pages#clients {:locale=>"zh-CN"} 
clients_zh_hk GET /zh-hk(/:locale)/pages/clients(.:format) pages#clients {:locale=>"zh-HK"} 
clients_zh_tw GET /zh-tw(/:locale)/pages/clients(.:format) pages#clients {:locale=>"zh-TW"} 
clients_fr GET (/:locale)/pages/clients(.:format) pages#clients {:locale=>"fr"} 
employes_en GET /en(/:locale)/pages/employes(.:format) pages#employes {:locale=>"en"} 
employes_ar GET /ar(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ar"} 
employes_az GET /az(/:locale)/pages/employes(.:format) pages#employes {:locale=>"az"} 
employes_bg GET /bg(/:locale)/pages/employes(.:format) pages#employes {:locale=>"bg"} 
employes_bn GET /bn(/:locale)/pages/employes(.:format) pages#employes {:locale=>"bn"} 
employes_bs GET /bs(/:locale)/pages/employes(.:format) pages#employes {:locale=>"bs"} 
employes_ca GET /ca(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ca"} 
employes_cs GET /cs(/:locale)/pages/employes(.:format) pages#employes {:locale=>"cs"} 
employes_da GET /da(/:locale)/pages/employes(.:format) pages#employes {:locale=>"da"} 
employes_de_ch GET /de-ch(/:locale)/pages/employes(.:format) pages#employes {:locale=>"de-CH"} 
employes_de GET /de(/:locale)/pages/employes(.:format) pages#employes {:locale=>"de"} 
employes_el GET /el(/:locale)/pages/employes(.:format) pages#employes {:locale=>"el"} 
employes_en_gb GET /en-gb(/:locale)/pages/employes(.:format) pages#employes {:locale=>"en-GB"} 
employes_es_mx GET /es-mx(/:locale)/pages/employes(.:format) pages#employes {:locale=>"es-MX"} 
employes_es GET /es(/:locale)/pages/employes(.:format) pages#employes {:locale=>"es"} 
employes_et GET /et(/:locale)/pages/employes(.:format) pages#employes {:locale=>"et"} 
employes_fa GET /fa(/:locale)/pages/employes(.:format) pages#employes {:locale=>"fa"} 
employes_fi GET /fi(/:locale)/pages/employes(.:format) pages#employes {:locale=>"fi"} 
employes_fr_ca GET /fr-ca(/:locale)/pages/employes(.:format) pages#employes {:locale=>"fr-CA"} 
employes_he GET /he(/:locale)/pages/employes(.:format) pages#employes {:locale=>"he"} 
employes_hr GET /hr(/:locale)/pages/employes(.:format) pages#employes {:locale=>"hr"} 
employes_hu GET /hu(/:locale)/pages/employes(.:format) pages#employes {:locale=>"hu"} 
employes_id GET /id(/:locale)/pages/employes(.:format) pages#employes {:locale=>"id"} 
employes_is GET /is(/:locale)/pages/employes(.:format) pages#employes {:locale=>"is"} 
employes_it GET /it(/:locale)/pages/employes(.:format) pages#employes {:locale=>"it"} 
employes_ja GET /ja(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ja"} 
employes_ko GET /ko(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ko"} 
employes_lt GET /lt(/:locale)/pages/employes(.:format) pages#employes {:locale=>"lt"} 
employes_lv GET /lv(/:locale)/pages/employes(.:format) pages#employes {:locale=>"lv"} 
employes_my GET /my(/:locale)/pages/employes(.:format) pages#employes {:locale=>"my"} 
employes_nb GET /nb(/:locale)/pages/employes(.:format) pages#employes {:locale=>"nb"} 
employes_nl GET /nl(/:locale)/pages/personeel(.:format) pages#employes {:locale=>"nl"} 
employes_nn_no GET /nn-no(/:locale)/pages/employes(.:format) pages#employes {:locale=>"nn-NO"} 
employes_no GET /no(/:locale)/pages/employes(.:format) pages#employes {:locale=>"no"} 
employes_pl GET /pl(/:locale)/pages/employes(.:format) pages#employes {:locale=>"pl"} 
employes_pt_br GET /pt-br(/:locale)/pages/employes(.:format) pages#employes {:locale=>"pt-BR"} 
employes_pt GET /pt(/:locale)/pages/employes(.:format) pages#employes {:locale=>"pt"} 
employes_ro GET /ro(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ro"} 
employes_ru GET /ru(/:locale)/pages/employes(.:format) pages#employes {:locale=>"ru"} 
employes_sk GET /sk(/:locale)/pages/employes(.:format) pages#employes {:locale=>"sk"} 
employes_sl GET /sl(/:locale)/pages/employes(.:format) pages#employes {:locale=>"sl"} 
employes_sr_rs GET /sr-rs(/:locale)/pages/employes(.:format) pages#employes {:locale=>"sr-RS"} 
employes_sr GET /sr(/:locale)/pages/employes(.:format) pages#employes {:locale=>"sr"} 
employes_sv GET /sv(/:locale)/pages/employes(.:format) pages#employes {:locale=>"sv"} 
employes_th GET /th(/:locale)/pages/employes(.:format) pages#employes {:locale=>"th"} 
employes_tr GET /tr(/:locale)/pages/employes(.:format) pages#employes {:locale=>"tr"} 
employes_uk GET /uk(/:locale)/pages/employes(.:format) pages#employes {:locale=>"uk"} 
employes_vi GET /vi(/:locale)/pages/employes(.:format) pages#employes {:locale=>"vi"} 
employes_zh_cn GET /zh-cn(/:locale)/pages/employes(.:format) pages#employes {:locale=>"zh-CN"} 
employes_zh_hk GET /zh-hk(/:locale)/pages/employes(.:format) pages#employes {:locale=>"zh-HK"} 
employes_zh_tw GET /zh-tw(/:locale)/pages/employes(.:format) pages#employes {:locale=>"zh-TW"} 
employes_fr GET (/:locale)/pages/employes(.:format)  pages#employes {:locale=>"fr"} 

以防萬一,我用這些寶石(他們可能有潛在的影響): - 寶石「設計,國際化」 - 寶石「設計」

所以我在這裏。如果您有什麼祕訣,我在聽:)(包括任何替代寶石route_translator)

回答

0

測試此:

locales = ["nl", "fr"] 
locales = Regexp.union(locales) 
scope "(:locale)", locale: locales do 
get 'pages/clients', as: :clients 
get 'pages/employes', as: :employes 
end 
1

您可以通過一個初始化配置RouteTranslator或使用環境的不同配置文件。

RouteTranslator.config do |config| 
    config.force_locale = true 
    config.locale_param_key = :my_locale 
end 

available_locales使用此來限制哪些URL應該生成的語言環境。接受一組字符串或符號。

嘗試添加available_locales選項到您的配置[:fr, :nl]

+0

謝謝詹姆斯。我在我的application.rb文件中添加了'config.i18n.available_locales = [:fr,:nl]',它起作用。 – doem