Commit 90378081fc8c25cff0a4cdd57184ac25ae12991d
Exists in
master
and in
29 other branches
Merge branch 'fix-i18n' into 'master'
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.
See merge request !686
Showing
2 changed files
with
28 additions
and
29 deletions
Show diff stats
app/controllers/public/search_controller.rb
| ... | ... | @@ -176,22 +176,24 @@ class SearchController < PublicController |
| 176 | 176 | end |
| 177 | 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 | 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 | 192 | render_not_found |
| 191 | 193 | return |
| 192 | 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 | 197 | @searching = {} |
| 196 | 198 | @titles = {} |
| 197 | 199 | @enabled_searches.each do |key, name| |
| ... | ... | @@ -203,7 +205,7 @@ class SearchController < PublicController |
| 203 | 205 | |
| 204 | 206 | def load_order |
| 205 | 207 | @order = 'more_recent' |
| 206 | - if AVAILABLE_SEARCHES.keys.include?(@asset.to_sym) | |
| 208 | + if available_searches.keys.include?(@asset.to_sym) | |
| 207 | 209 | available_orders = asset_class(@asset)::SEARCH_FILTERS[:order] |
| 208 | 210 | @order = params[:order] if available_orders.include?(params[:order]) |
| 209 | 211 | 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 | ... | ... |