let page model support i18n

This commit is contained in:
Wen-Tien Chang committed 2009-06-19 17:31:10 +08:00
1 parent bd9ef6d286
commit db8d2bfa8f
4 files changed
+29 -5

No files matched your search

+13 -1
View File
@@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
before_filter :set_locale
filter_parameter_logging :password
Liquid::Template.register_filter(SnippetFilter)
@@ -11,7 +13,7 @@ class ApplicationController < ActionController::Base
if @page
@layout = @page.layout
@page_options ||= {}
@page_content = Liquid::Template.parse(@page.content).render(@page_options)
@page_content = Liquid::Template.parse( @page.read_attribute( "content_#{I18n.locale}" ) ).render(@page_options)
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
else
@@ -19,4 +21,14 @@ class ApplicationController < ActionController::Base
end
end
def set_locale
# update session if passed
if params[:locale] && VALID_LOCALES.include?( params[:locale] )
session[:locale] = params[:locale]
end
# set locale based on session or default
I18n.locale = session[:locale] || I18n.default_locale
end
end