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