我覺得我錯過了一些非常簡單的事情,並且我一直在關注這個問題。使用Rails進行靜態頁面的國際化
我目前的國際化工作貫穿我的應用程序。翻譯工作和路線完美地工作。至少,除了通往我的兩個靜態頁面(我的「關於」和「常見問題」頁面)的路線以外,大多數網站都可以工作。
整個應用程序的其他所有鏈接指向適當的本地化路線。例如,如果我選擇「法語」作爲我的語言,鏈接指向適當的「(/:locale)/controller(.:format)」。「但是,儘管我在整個應用程序中進行了更改,但「關於」和「常見問題解答」的鏈接拒絕指向「../fr/static/about」,並始終指向「/ static/about」。
爲了讓事情變得更奇怪,當我運行耙路線時,我看到: 「GET(/:locale)/static/:permalink(.:format)pages#show {:locale =>/en | fr /}」
當我手動輸入「../fr/static/about」時,頁面翻譯完美。
我的routes文件:
devise_for :users
scope "(:locale)", :locale => /en|fr/ do
get 'static/:permalink', :controller => 'pages', :action => 'show'
resources :places, only: [:index, :show, :destroy]
resources :homes, only: [:index, :show]
match '/:locale' => 'places#index'
get '/'=>'places#index',:as=>"root"
end
我的ApplicationController:
before_filter :set_locale
def set_locale
I18n.locale=params[:locale]||I18n.default_locale
end
def default_url_options(options={})
logger.debug "default_url_options is passed options: #{options.inspect}\n"
{ :locale => I18n.locale }
end
和我的頁面控制器:
class PagesController < ApplicationController
before_filter :validate_page
PAGES = ['about_us', 'faq']
def show
render params[:permalink]
end
def validate_page
redirect_to :status => 404 unless PAGES.include?(params[:permalink])
end
end
我會任何幫助非常感謝......這是隻是那些日子之一。
編輯:感謝特里慢跑我包括意見。
<div class="container-fluid nav-collapse">
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= t(:'navbar.about') %><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><%=link_to t(:'navbar.about_us'), "/static/about_us"%></li>
<li><%=link_to t(:'navbar.faq'), "/static/faq"%></li>
<li><%=link_to t(:'navbar.blog'), '#' %></li>
</ul>
</li>
呈現鏈接的視圖如何? –