From aed63bb6b431105d5ff2081b14f4c2d5d9dc0051 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 2 Oct 2015 10:34:27 -0300 Subject: [PATCH] search: resolve translations at runtime --- app/controllers/public/search_controller.rb | 24 +++++++++++++----------- app/helpers/search_helper.rb | 33 +++++++++++++++------------------ 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index dbb3239..c059876 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -176,22 +176,24 @@ class SearchController < PublicController end end - AVAILABLE_SEARCHES = ActiveSupport::OrderedHash[ - :articles, _('Contents'), - :people, _('People'), - :communities, _('Communities'), - :enterprises, _('Enterprises'), - :products, _('Products and Services'), - :events, _('Events'), - ] + def available_searches + @available_searches ||= ActiveSupport::OrderedHash[ + :articles, _('Contents'), + :people, _('People'), + :communities, _('Communities'), + :enterprises, _('Enterprises'), + :products, _('Products and Services'), + :events, _('Events'), + ] + end def load_search_assets - if AVAILABLE_SEARCHES.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}") + if available_searches.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}") render_not_found return end - @enabled_searches = AVAILABLE_SEARCHES.select {|key, name| environment.disabled?("disable_asset_#{key}") } + @enabled_searches = available_searches.select {|key, name| environment.disabled?("disable_asset_#{key}") } @searching = {} @titles = {} @enabled_searches.each do |key, name| @@ -203,7 +205,7 @@ class SearchController < PublicController def load_order @order = 'more_recent' - if AVAILABLE_SEARCHES.keys.include?(@asset.to_sym) + if available_searches.keys.include?(@asset.to_sym) available_orders = asset_class(@asset)::SEARCH_FILTERS[:order] @order = params[:order] if available_orders.include?(params[:order]) end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 2dfc4f5..219678b 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -5,24 +5,21 @@ module SearchHelper BLOCKS_SEARCH_LIMIT = 24 MULTIPLE_SEARCH_LIMIT = 8 - FILTERS_TRANSLATIONS = { - :order => _('Order'), - :display => _('Display') - } - - FILTERS_OPTIONS_TRANSLATION = { - :order => { - 'more_popular' => _('More popular'), - 'more_active' => _('More active'), - 'more_recent' => _('More recent'), - 'more_comments' => _('More comments') - }, - :display => { - 'map' => _('Map'), - 'full' => _('Full'), - 'compact' => _('Compact') + def filters_options_translation + @filters_options_translation ||= { + :order => { + 'more_popular' => _('More popular'), + 'more_active' => _('More active'), + 'more_recent' => _('More recent'), + 'more_comments' => _('More comments') + }, + :display => { + 'map' => _('Map'), + 'full' => _('Full'), + 'compact' => _('Compact') + } } - } + end COMMON_PROFILE_LIST_BLOCK = [ :enterprises, @@ -100,7 +97,7 @@ module SearchHelper if options.size <= 1 return else - options = options.map {|option| [FILTERS_OPTIONS_TRANSLATION[name][option], option]} + options = options.map {|option| [filters_options_translation[name][option], option]} options = options_for_select(options, :selected => (params[name] || default)) select_tag(name, options) end -- libgit2 0.21.2