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
+7 -1
View File
@@ -1,8 +1,14 @@
class Page < CouchFoo::Base
property :lang, String
property :name, String
property :parent_page_id, String
property :content, String
property :content_zh_tw, String
property :content_en, String
property :content_ja, String
# TODO: more language can dynamic added
property :layout_id, String
property :layout_name, String
property :use_engine, String
+7 -2
View File
@@ -9,8 +9,13 @@
</p>
<p>
<%= f.label :content, "Content" %>
<%= f.text_area :content, :size => '100x30' %>
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p>
<p>
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
<%= f.text_area "content_zh_tw", :size => '100x30' %>
</p>
<p>