app/controllers/alchemy/base_controller.rb in alchemy_cms-2.5.0.b5 vs app/controllers/alchemy/base_controller.rb in alchemy_cms-2.5.0.b9

- old
+ new

@@ -8,11 +8,11 @@ before_filter :set_current_site before_filter :set_language before_filter :mailer_set_url_options - helper_method :current_server, :current_site, :t + helper_method :current_server, :current_site # Returns a host string with the domain the app is running on. def current_server # For local development server if request.port != 80 @@ -37,13 +37,13 @@ def raise_not_found_error raise ActionController::RoutingError.new('Not Found') end - # Overriding +I18n+s default +t+ helper, so we can pass it through +Alchemy::I18n+ - def t(key, *args) - ::Alchemy::I18n.t(key, *args) + # Shortcut for Alchemy::I18n.translate method + def _t(key, *args) + I18n.t(key, *args) end private # Returns the current site. @@ -72,14 +72,12 @@ ::I18n.locale = session[:current_locale] elsif params[:locale].present? && ::I18n.available_locales.include?(params[:locale].to_sym) session[:current_locale] = ::I18n.locale = params[:locale] elsif current_user && current_user.language.present? ::I18n.locale = current_user.language - elsif Rails.env == 'test' # OMG I hate to do this. But it helps... - ::I18n.locale = 'en' else - ::I18n.locale = request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /^[a-z]{2}/).try(:first) + ::I18n.locale = request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /^[a-z]{2}/).try(:first) || ::I18n.default_locale end end # Sets the language for rendering pages in pages controller. # @@ -115,11 +113,11 @@ def load_language_from(language_code_or_id) Language.find_by_id(language_code_or_id) || Language.find_by_code(language_code_or_id) end def load_language_default - Language.get_default + Language.get_default || raise(DefaultLanguageNotFoundError) end def store_language_in_session(language) if language && language.id session[:language_id] = language.id @@ -199,22 +197,22 @@ if request.referer == alchemy.login_url render :file => Rails.root.join('public/422'), :status => 422 elsif request.xhr? respond_to do |format| format.js { - render :js => "Alchemy.growl('#{t('You are not authorized')}', 'warning'); Alchemy.Buttons.enable();" + render :js => "Alchemy.growl('#{_t('You are not authorized')}', 'warning'); Alchemy.Buttons.enable();" } format.html { - render :partial => 'alchemy/admin/partials/flash', :locals => {:message => t('You are not authorized'), :flash_type => 'warning'} + render :partial => 'alchemy/admin/partials/flash', :locals => {:message => _t('You are not authorized'), :flash_type => 'warning'} } end else - flash[:error] = t('You are not authorized') + flash[:error] = _t('You are not authorized') redirect_to alchemy.admin_dashboard_path end end else - flash[:info] = t('Please log in') + flash[:info] = _t('Please log in') if request.xhr? render :action => :permission_denied else store_location redirect_to alchemy.login_path