Sha256: b8d0b42e672987aa1339455a8f5301fdc6e41a86d3562916685f0f4175501c6d
Contents?: true
Size: 739 Bytes
Versions: 3
Compression:
Stored size: 739 Bytes
Contents
# frozen_string_literal: true require_dependency "decidim/application_controller" module Decidim # A controller to allow users switching their locale. class LocalesController < ApplicationController 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
3 entries across 3 versions & 1 rubygems