Sha256: 04d96bc0929ae2cff692872d275bd2fa97f8e8259704671b0326275cbe7d1cbc

Contents?: true

Size: 761 Bytes

Versions: 35

Compression:

Stored size: 761 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

35 entries across 35 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.5 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.4 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.3 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.2 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.1.rc1 app/controllers/decidim/locales_controller.rb
decidim-core-0.23.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.22.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.21.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.20.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.20.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.19.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.18.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.19.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.17.2 app/controllers/decidim/locales_controller.rb
decidim-core-0.18.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.17.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.16.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.17.0 app/controllers/decidim/locales_controller.rb