Sha256: fbfed4f52d11db407e7f8898e45613fa67780f73b41104a280f57ce9fe6b5e09

Contents?: true

Size: 760 Bytes

Versions: 37

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # A controller to allow users switching their locale.
  class LocalesController < Decidim::ApplicationController
    skip_before_action :store_current_location

    def create
      enforce_permission_to :create, :locales
      current_user.update!(locale: params["locale"]) if current_user && params["locale"] && available_locales.include?(params["locale"])

      redirect_to referer_with_new_locale
    end

    private

    def referer_with_new_locale
      uri = URI(request.referer || "/")
      query = uri.query.to_s.gsub(/locale=[a-zA-Z\-]{2,5}/, "")
      params = URI.decode_www_form(query) << ["locale", current_locale]
      uri.query = URI.encode_www_form(params)

      uri.to_s
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.8 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.7 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.6 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.10 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.9 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.5 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.8 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.4 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.3 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.7 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.5 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.2 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.4 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.3 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.0.rc2 app/controllers/decidim/locales_controller.rb
decidim-core-0.27.0.rc1 app/controllers/decidim/locales_controller.rb
decidim-core-0.26.2 app/controllers/decidim/locales_controller.rb