[Git][noosfero/noosfero][master] 2 commits: search: resolve translations at runtime

Larissa Reis gitlab at gitlab.com
Fri Oct 2 15:50:51 BRT 2015


Larissa Reis pushed to branch master at Noosfero / noosfero


Commits:
aed63bb6 by Antonio Terceiro at 2015-10-02T10:45:13Z
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.

- - - - -
90378081 by Larissa Reis at 2015-10-02T18:50:30Z
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
- - - - -


2 changed files:

- app/controllers/public/search_controller.rb
- app/helpers/search_helper.rb


Changes:

=====================================
app/controllers/public/search_controller.rb
=====================================
--- 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


=====================================
app/helpers/search_helper.rb
=====================================
--- 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



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/9ecec837578161ecf82b6fc542b1bfab332c4f45...90378081fc8c25cff0a4cdd57184ac25ae12991d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151002/a3360d9a/attachment.html>


More information about the Noosfero-dev mailing list