Sha256: 2b33c0ff5d9e8213ecc6a01a0527eb7112db664a832f61870f656cc77fc8accd

Contents?: true

Size: 1.04 KB

Versions: 22

Compression:

Stored size: 1.04 KB

Contents

module Alchemy
  # Handles locale redirects
  #
  # If the current URL has a locale prefix, but should not have one it redirects
  # to url without locale prefix.
  #
  # Situations we don't want a locale prefix:
  #
  # 1. If only one language is published
  # 2. If the requested locale is the current default locale
  #
  module LocaleRedirects
    extend ActiveSupport::Concern

    included do
      before_action :enforce_no_locale,
        if: :locale_prefix_not_allowed?,
        only: [:index, :show]
    end

    private

    # Redirects to requested action without locale prefixed
    def enforce_no_locale
      redirect_permanently_to additional_params.merge(locale: nil)
    end

    # Is the requested locale allowed?
    #
    # If Alchemy is not in multi language mode or the requested locale is the default locale,
    # then we want to redirect to a non prefixed url.
    #
    def locale_prefix_not_allowed?
      params[:locale].present? && !multi_language? ||
        params[:locale].presence == ::I18n.default_locale.to_s
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.6 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.5 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.4 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.3 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.2 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.1 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-4.0.0.beta app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.6.0 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.5.0 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.4.2 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.5.0.rc2 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.5.0.rc1 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.4.1 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.3.3 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.3.2 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.4.0 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.4.0.rc1 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.3.1 app/controllers/concerns/alchemy/locale_redirects.rb
alchemy_cms-3.3.0 app/controllers/concerns/alchemy/locale_redirects.rb