Commit ac24e531aedb1ae7a8a7286192050a6a227e29b0

Authored by Antonio Terceiro
1 parent 596f9f48
Exists in stable-1.2

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.

(cherry picked from commit aed63bb6b431105d5ff2081b14f4c2d5d9dc0051)
app/controllers/public/search_controller.rb
... ... @@ -178,22 +178,24 @@ class SearchController < PublicController
178 178 end
179 179 end
180 180  
181   - AVAILABLE_SEARCHES = ActiveSupport::OrderedHash[
182   - :articles, _('Contents'),
183   - :people, _('People'),
184   - :communities, _('Communities'),
185   - :enterprises, _('Enterprises'),
186   - :products, _('Products and Services'),
187   - :events, _('Events'),
188   - ]
  181 + def available_searches
  182 + @available_searches ||= ActiveSupport::OrderedHash[
  183 + :articles, _('Contents'),
  184 + :people, _('People'),
  185 + :communities, _('Communities'),
  186 + :enterprises, _('Enterprises'),
  187 + :products, _('Products and Services'),
  188 + :events, _('Events'),
  189 + ]
  190 + end
189 191  
190 192 def load_search_assets
191   - if AVAILABLE_SEARCHES.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}")
  193 + if available_searches.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}")
192 194 render_not_found
193 195 return
194 196 end
195 197  
196   - @enabled_searches = AVAILABLE_SEARCHES.select {|key, name| environment.disabled?("disable_asset_#{key}") }
  198 + @enabled_searches = available_searches.select {|key, name| environment.disabled?("disable_asset_#{key}") }
197 199 @searching = {}
198 200 @titles = {}
199 201 @enabled_searches.each do |key, name|
... ... @@ -205,7 +207,7 @@ class SearchController < PublicController
205 207  
206 208 def load_order
207 209 @order = 'more_recent'
208   - if AVAILABLE_SEARCHES.keys.include?(@asset.to_sym)
  210 + if available_searches.keys.include?(@asset.to_sym)
209 211 available_orders = asset_class(@asset)::SEARCH_FILTERS[:order]
210 212 @order = params[:order] if available_orders.include?(params[:order])
211 213 end
... ...
app/helpers/search_helper.rb
... ... @@ -5,24 +5,21 @@ module SearchHelper
5 5 BLOCKS_SEARCH_LIMIT = 24
6 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 24 COMMON_PROFILE_LIST_BLOCK = [
28 25 :enterprises,
... ... @@ -100,7 +97,7 @@ module SearchHelper
100 97 if options.size <= 1
101 98 return
102 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 101 options = options_for_select(options, :selected => (params[name] || default))
105 102 select_tag(name, options)
106 103 end
... ...