app/controllers/umlaut/controller_behavior.rb in umlaut-3.3.1 vs app/controllers/umlaut/controller_behavior.rb in umlaut-4.0.0.beta1

- old
+ new

@@ -1,9 +1,12 @@ # All behavior from UmlautController is extracted into this module, # so that we can generate a local UmlautController that includes # this module, and local app can configure or over-ride default behavior. # +# +# This is really only intended to be included'd by UmlautController; +# other controllers may sub-class UmlautController module Umlaut::ControllerBehavior extend ActiveSupport::Concern include UmlautConfigurable include Umlaut::ErrorHandling @@ -11,15 +14,41 @@ included do |controller| controller.helper Umlaut::Helper # global umlaut view helpers # init default configuration values UmlautConfigurable.set_default_configuration!(controller.umlaut_config) + # Set locale from request param + controller.before_filter :set_locale end + + # Set the current locale based on request param umlaut.locale + # Local app can override this in UmlautController if you'd like to + # base locale on HTTP headers or IP address or other things. + def set_locale + I18n.locale = params['umlaut.locale'.to_sym] || I18n.default_locale + end + + # Rails over-ride to ensure locale is always included in + # generated URLs. We choose to explicitly include locale's + # only for non-default locale. + # Local app may override this in UmlautController to make + # other choices. + def default_url_options(*arguments) + if I18n.locale == I18n.default_locale + # Don't add in param for default locale + super + else + super.merge({ 'umlaut.locale'.to_sym => I18n.locale }) + end + end + + + # Returns the search layout name unless this is an XML HTTP Request. def search_layout_except_xhr @layout_name ||= (request.xhr? || params["X-Requested-With"] == "XmlHttpRequest") ? - nil : umlaut_config.search_layout + false : umlaut_config.search_layout end protected :search_layout_except_xhr # We intentionally use a method calculated at request-time for layout, # so it can be changed in config at request-time.