Internationalization of static pages with Rails
- by Gavin
I feel like I'm missing something really simple and I keep spinning my wheels on this problem.
I currently have internationalization working throughout my app. The translations work and the routes work perfectly. At least, most of the site works with the exception of the routes to my two static pages, my "About" and "FAQ" pages.
Every other link throughout the app points to the proper localized route. For example if I select "french" as my language, links point to the appropriate "(/:locale)/controller(.:format)." However, despite the changes I make throughout the app my links for the "About" and "FAQ" refuse to point to "../fr/static/about" and always point to "/static/about."
To make matters stranger, when I run rake routes I see:
"GET (/:locale)/static/:permalink(.:format) pages#show {:locale=/en|fr/}"
and when I manually type in "../fr/static/about" the page translates perfectly.
My Routes file:
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
My 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
and My Pages Controller:
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
I'd be very grateful for any help ... it's just been one of those days.
Edit: Thanks to Terry for jogging me to include views.
<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>