Sha256: b10bb30a4ead9bbf1d90ae8b32e652ffbae36ea8053071aa6a5f22ccd12e0c5a

Contents?: true

Size: 743 Bytes

Versions: 10

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_attributes!(locale: params["locale"])
      end

      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

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.8.4 app/controllers/decidim/locales_controller.rb
decidim-core-0.8.3 app/controllers/decidim/locales_controller.rb
decidim-core-0.8.2 app/controllers/decidim/locales_controller.rb
decidim-core-0.8.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.8.0 app/controllers/decidim/locales_controller.rb
decidim-core-0.7.4 app/controllers/decidim/locales_controller.rb
decidim-core-0.7.3 app/controllers/decidim/locales_controller.rb
decidim-core-0.7.2 app/controllers/decidim/locales_controller.rb
decidim-core-0.7.1 app/controllers/decidim/locales_controller.rb
decidim-core-0.7.0 app/controllers/decidim/locales_controller.rb