Sha256: bc75ae6831749d78ab230bd0221cbd9fa880be5146fdd4c5e3177ad3002d56b1

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

module SolidusAdmin::ControllerHelpers::Locale
  extend ActiveSupport::Concern
  include Spree::Admin::SetsUserLanguageLocaleKey

  included do
    before_action :set_locale
    before_action :update_user_locale
  end

  private

  def update_user_locale
    requested_locale = params[:switch_to_locale] or return

    if requested_locale.to_sym != user_locale
      session[set_user_language_locale_key] = requested_locale

      flash[:notice] = t('spree.locale_changed')
      redirect_to url_for(request.params.except(:switch_to_locale))
    end
  end

  def user_locale
    session[set_user_language_locale_key] || I18n.default_locale
  end

  def set_locale
    I18n.locale = user_locale
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_admin-0.0.2 app/controllers/solidus_admin/controller_helpers/locale.rb
solidus_admin-0.0.1 app/controllers/solidus_admin/controller_helpers/locale.rb