Starting controllers internationalization
Jorge Calás Lozano
committed May 09, 2011
commit cbac926d222c0157abed47e8ce89767df97a5442
Showing 4
changed files with
53 additions
and 33 deletions
app/controllers/cms_admin/base_controller.rb
+15
-12
| @@ | @@ -1,41 +1,44 @@ |
| class CmsAdmin::BaseController < ApplicationController | |
| - | |
| + | |
| protect_from_forgery | |
| - | |
| + | |
| # Authentication module must have #authenticate method | |
| include ComfortableMexicanSofa.config.authentication.to_s.constantize | |
| - | |
| + | |
| before_filter :authenticate, | |
| :load_admin_cms_site, | |
| :load_fixtures | |
| - | |
| + | |
| layout 'cms_admin' | |
| - | |
| + | |
| protected | |
| - | |
| + | |
| def load_admin_cms_site | |
| hostname = request.host.downcase | |
| @cms_site = Cms::Site.find_by_hostname!(hostname) | |
| - | |
| + | |
| rescue ActiveRecord::RecordNotFound | |
| unless ComfortableMexicanSofa.config.enable_multiple_sites | |
| if Cms::Site.count == 0 | |
| - | @cms_site = Cms::Site.create!(:label => 'Default Site', :hostname => hostname) |
| + | @cms_site = Cms::Site.create!(:label => I18n.t('cms.sites.default_site', |
| + | :default => 'Default Site'), :hostname => hostname) |
| else | |
| @cms_site = Cms::Site.first | |
| @cms_site.update_attribute(:hostname, hostname) | |
| end | |
| end | |
| - | |
| + | |
| unless @cms_site | |
| - | flash[:error] = 'No Site defined for this hostname. Create it now.' |
| + | flash[:error] = I18n.t('cms.controllers.errors.no_site_for_this_hostname', |
| + | :default => 'No Site defined for this hostname. Create it now.') |
| return redirect_to(cms_admin_sites_path) | |
| end | |
| end | |
| - | |
| + | |
| def load_fixtures | |
| return unless ComfortableMexicanSofa.config.enable_fixtures | |
| ComfortableMexicanSofa::Fixtures.import_all(@cms_site.hostname) | |
| - | flash.now[:error] = 'CMS Fixtures are enabled. All changes done here will be discarded.' |
| + | flash.now[:error] = I18n.t('cms.controllers.errors.fixtures_enabled', |
| + | :default => 'CMS Fixtures are enabled. All changes done here will be discarded.') |
| end | |
| end | |
app/controllers/cms_admin/layouts_controller.rb
+6
-6
| @@ | @@ -18,25 +18,25 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController |
| def create | |
| @cms_layout.save! | |
| - | flash[:notice] = 'Layout created' |
| + | flash[:notice] = I18n.t('cms.controllers.layouts.layout_created', :default => 'Layout created') |
| redirect_to :action => :edit, :id => @cms_layout | |
| rescue ActiveRecord::RecordInvalid | |
| - | flash.now[:error] = 'Failed to create layout' |
| + | flash.now[:error] = I18n.t('cms.controllers.layouts.failed_to_create_layout', :default => 'Failed to create layout') |
| render :action => :new | |
| end | |
| def update | |
| @cms_layout.update_attributes!(params[:cms_layout]) | |
| - | flash[:notice] = 'Layout updated' |
| + | flash[:notice] = I18n.t('cms.controllers.layouts.layout_updated', :default => 'Layout updated') |
| redirect_to :action => :edit, :id => @cms_layout | |
| rescue ActiveRecord::RecordInvalid | |
| - | flash.now[:error] = 'Failed to update layout' |
| + | flash.now[:error] = I18n.t('cms.controllers.layouts.failed_to_update_layout', :default => 'Failed to update layout') |
| render :action => :edit | |
| end | |
| def destroy | |
| @cms_layout.destroy | |
| - | flash[:notice] = 'Layout deleted' |
| + | flash[:notice] = I18n.t('cms.controllers.layouts.layout_deleted', :default => 'Layout Deleted') |
| redirect_to :action => :index | |
| end | |
| @@ | @@ -51,7 +51,7 @@ protected |
| def load_cms_layout | |
| @cms_layout = @cms_site.layouts.find(params[:id]) | |
| rescue ActiveRecord::RecordNotFound | |
| - | flash[:error] = 'Layout not found' |
| + | flash[:error] = I18n.t('cms.controllers.errors.layout_not_found', :default => 'Layout Not Found') |
| redirect_to :action => :index | |
| end | |
app/controllers/cms_content_controller.rb
+15
-15
| @@ | @@ -1,61 +1,61 @@ |
| class CmsContentController < ApplicationController | |
| - | |
| + | |
| before_filter :load_cms_site | |
| before_filter :load_fixtures | |
| before_filter :load_cms_page, :only => :render_html | |
| before_filter :load_cms_layout, :only => [:render_css, :render_js] | |
| - | |
| + | |
| caches_page :render_css, :render_js, :if => Proc.new { |c| ComfortableMexicanSofa.config.enable_caching } | |
| - | |
| + | |
| def render_html(status = 200) | |
| if layout = @cms_page.layout | |
| app_layout = layout.app_layout.blank?? false : layout.app_layout | |
| render :inline => @cms_page.content, :layout => app_layout, :status => status | |
| else | |
| - | render :text => 'Layout Not Found', :status => 404 |
| + | render :text => I18n.t('cms.controllers.errors.layout_not_found', :default => 'Layout Not Found'), :status => 404 |
| end | |
| end | |
| - | |
| + | |
| def render_css | |
| render :text => @cms_layout.css, :content_type => 'text/css' | |
| end | |
| - | |
| + | |
| def render_js | |
| render :text => @cms_layout.js, :content_type => 'text/javascript' | |
| end | |
| - | |
| + | |
| protected | |
| - | |
| + | |
| def load_fixtures | |
| return unless ComfortableMexicanSofa.config.enable_fixtures | |
| ComfortableMexicanSofa::Fixtures.import_all(@cms_site.hostname) | |
| end | |
| - | |
| + | |
| def load_cms_site | |
| @cms_site = if ComfortableMexicanSofa.config.enable_multiple_sites | |
| Cms::Site.find_by_hostname(request.host.downcase) | |
| else | |
| Cms::Site.first | |
| end | |
| - | render :text => 'Site Not Found', :status => 404 if !@cms_site |
| + | render :text => I18n.t('cms.controllers.errors.site_not_found', :default => 'Site Not Found'), :status => 404 if !@cms_site |
| end | |
| - | |
| + | |
| def load_cms_page | |
| @cms_page = @cms_site.pages.published.find_by_full_path!("/#{params[:cms_path]}") | |
| return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page | |
| - | |
| + | |
| rescue ActiveRecord::RecordNotFound | |
| if @cms_page = @cms_site.pages.published.find_by_full_path('/404') | |
| render_html(404) | |
| else | |
| - | render :text => 'Page Not Found', :status => 404 |
| + | render :text => I18n.t('cms.controllers.errors.page_not_found', :default => 'Page Not Found'), :status => 404 |
| end | |
| end | |
| - | |
| + | |
| def load_cms_layout | |
| @cms_layout = @cms_site.layouts.find_by_slug!(params[:id]) | |
| rescue ActiveRecord::RecordNotFound | |
| render :nothing => true, :status => 404 | |
| end | |
| - | |
| + | |
| end | |
config/locales/es.yml
+17
-0
| @@ | @@ -1,3 +1,4 @@ |
| + | # encoding: utf-8 |
| es: | |
| cms: | |
| sections: | |
| @@ | @@ -61,3 +62,19 @@ es: |
| editing_site: "Editando Sitio" | |
| create_site: "Crear Sitio" | |
| update_site: "Actualizar Sitio" | |
| + | |
| + | controllers: |
| + | sites: |
| + | default_site: "Sitio Predeterminado" |
| + | layouts: |
| + | layout_created: "Diseño Creado" |
| + | failed_to_create_layout: "El diseño NO ha podido ser Creado" |
| + | layout_updated: "Diseño Actualizado" |
| + | failed_to_update_layout: "El diseño NO ha podido ser Actualizado" |
| + | layout_deleted: "Diseñó Eliminado" |
| + | |
| + | errors: |
| + | layout_not_found: "Diseño no encontrado" |
| + | site_not_found: "Sitio no encontrado" |
| + | page_not_found: "Página no encontrada" |
| + | no_site_for_this_hostname: "No se ha creado un sitio para esta dirección. Créalo ahora." |