Commit aed63bb6b431105d5ff2081b14f4c2d5d9dc0051

Authored by Antonio Terceiro
1 parent 9ac9e0ab

search: resolve translations at runtime

If you resolve the translation calls -- _("...") -- at load time they
will not be translated based on the current user's language.

SearchHelper::FILTERS_TRANSLATIONS was not used anywhere, so it got
removed.
app/controllers/public/search_controller.rb
@@ -176,22 +176,24 @@ class SearchController < PublicController @@ -176,22 +176,24 @@ class SearchController < PublicController
176 end 176 end
177 end 177 end
178 178
179 - AVAILABLE_SEARCHES = ActiveSupport::OrderedHash[  
180 - :articles, _('Contents'),  
181 - :people, _('People'),  
182 - :communities, _('Communities'),  
183 - :enterprises, _('Enterprises'),  
184 - :products, _('Products and Services'),  
185 - :events, _('Events'),  
186 - ] 179 + def available_searches
  180 + @available_searches ||= ActiveSupport::OrderedHash[
  181 + :articles, _('Contents'),
  182 + :people, _('People'),
  183 + :communities, _('Communities'),
  184 + :enterprises, _('Enterprises'),
  185 + :products, _('Products and Services'),
  186 + :events, _('Events'),
  187 + ]
  188 + end
187 189
188 def load_search_assets 190 def load_search_assets
189 - if AVAILABLE_SEARCHES.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}") 191 + if available_searches.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}")
190 render_not_found 192 render_not_found
191 return 193 return
192 end 194 end
193 195
194 - @enabled_searches = AVAILABLE_SEARCHES.select {|key, name| environment.disabled?("disable_asset_#{key}") } 196 + @enabled_searches = available_searches.select {|key, name| environment.disabled?("disable_asset_#{key}") }
195 @searching = {} 197 @searching = {}
196 @titles = {} 198 @titles = {}
197 @enabled_searches.each do |key, name| 199 @enabled_searches.each do |key, name|
@@ -203,7 +205,7 @@ class SearchController < PublicController @@ -203,7 +205,7 @@ class SearchController < PublicController
203 205
204 def load_order 206 def load_order
205 @order = 'more_recent' 207 @order = 'more_recent'
206 - if AVAILABLE_SEARCHES.keys.include?(@asset.to_sym) 208 + if available_searches.keys.include?(@asset.to_sym)
207 available_orders = asset_class(@asset)::SEARCH_FILTERS[:order] 209 available_orders = asset_class(@asset)::SEARCH_FILTERS[:order]
208 @order = params[:order] if available_orders.include?(params[:order]) 210 @order = params[:order] if available_orders.include?(params[:order])
209 end 211 end
app/helpers/search_helper.rb
@@ -5,24 +5,21 @@ module SearchHelper @@ -5,24 +5,21 @@ module SearchHelper
5 BLOCKS_SEARCH_LIMIT = 24 5 BLOCKS_SEARCH_LIMIT = 24
6 MULTIPLE_SEARCH_LIMIT = 8 6 MULTIPLE_SEARCH_LIMIT = 8
7 7
8 - FILTERS_TRANSLATIONS = {  
9 - :order => _('Order'),  
10 - :display => _('Display')  
11 - }  
12 -  
13 - FILTERS_OPTIONS_TRANSLATION = {  
14 - :order => {  
15 - 'more_popular' => _('More popular'),  
16 - 'more_active' => _('More active'),  
17 - 'more_recent' => _('More recent'),  
18 - 'more_comments' => _('More comments')  
19 - },  
20 - :display => {  
21 - 'map' => _('Map'),  
22 - 'full' => _('Full'),  
23 - 'compact' => _('Compact') 8 + def filters_options_translation
  9 + @filters_options_translation ||= {
  10 + :order => {
  11 + 'more_popular' => _('More popular'),
  12 + 'more_active' => _('More active'),
  13 + 'more_recent' => _('More recent'),
  14 + 'more_comments' => _('More comments')
  15 + },
  16 + :display => {
  17 + 'map' => _('Map'),
  18 + 'full' => _('Full'),
  19 + 'compact' => _('Compact')
  20 + }
24 } 21 }
25 - } 22 + end
26 23
27 COMMON_PROFILE_LIST_BLOCK = [ 24 COMMON_PROFILE_LIST_BLOCK = [
28 :enterprises, 25 :enterprises,
@@ -100,7 +97,7 @@ module SearchHelper @@ -100,7 +97,7 @@ module SearchHelper
100 if options.size <= 1 97 if options.size <= 1
101 return 98 return
102 else 99 else
103 - options = options.map {|option| [FILTERS_OPTIONS_TRANSLATION[name][option], option]} 100 + options = options.map {|option| [filters_options_translation[name][option], option]}
104 options = options_for_select(options, :selected => (params[name] || default)) 101 options = options_for_select(options, :selected => (params[name] || default))
105 select_tag(name, options) 102 select_tag(name, options)
106 end 103 end