Sha256: 5b6733e2e4c399237ebcb70421f0e5a583c86bdf85ea7e9f48508c1c4efad1c7

Contents?: true

Size: 743 Bytes

Versions: 24

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # A controller to allow users switching their locale.
  class LocalesController < Decidim::ApplicationController
    authorize_resource :locales, class: false

    def create
      if current_user && params["locale"] && available_locales.include?(params["locale"])
        current_user.update_attribute(:locale, params["locale"])
      end

      redirect_to referer_with_new_locale
    end

    private

    def referer_with_new_locale
      uri = URI(request.referrer || "/")
      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

24 entries across 24 versions & 2 rubygems

Version Path
decidim-core-0.6.8 app/controllers/decidim/locales_controller.rb
decidim-0.6.8 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.7 app/controllers/decidim/locales_controller.rb
decidim-0.6.7 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.6 app/controllers/decidim/locales_controller.rb
decidim-0.6.6 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.5 app/controllers/decidim/locales_controller.rb
decidim-0.6.5 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.4 app/controllers/decidim/locales_controller.rb
decidim-0.6.4 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.3 app/controllers/decidim/locales_controller.rb
decidim-0.6.3 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.2 app/controllers/decidim/locales_controller.rb
decidim-0.6.2 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.1 app/controllers/decidim/locales_controller.rb
decidim-0.6.1 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.6.0 app/controllers/decidim/locales_controller.rb
decidim-0.6.0 decidim-core/app/controllers/decidim/locales_controller.rb
decidim-core-0.5.1 app/controllers/decidim/locales_controller.rb
decidim-0.5.1 decidim-core/app/controllers/decidim/locales_controller.rb