Basic locale check

This commit is contained in:
Yuki 2015-05-26 08:56:40 +05:30
parent a5927cefa0
commit 69a1bb32f4
3 changed files with 27 additions and 0 deletions

View File

@ -4,9 +4,28 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :check_locale
before_filter :banned?
# check if user got hit by the banhammer of doom
def check_locale
if params[:hl].nil?
if current_user.present?
I18n.locale = current_user.locale
elsif not cookies[:hl].nil?
I18n.locale = cookies[:hl]
end
else
I18n.locale = params[:hl]
if current_user.present?
current_user.locale = I18n.locale
current_user.save!
end
end
cookies[:hl] = I18n.locale #unless cookies[:allow_cookies].nil? # some EU cookie bullsh-
end
def banned?
if current_user.present? && current_user.banned?
name = current_user.screen_name

View File

@ -24,6 +24,9 @@ module Justask
# Use Sidekiq for background jobs
config.active_job.queue_adapter = :sidekiq
config.i18n.default_locale = "en"
config.i18n.fallbacks = true
# DEPRECATION WARNING: Currently, Active Record suppresses errors raised
# within `after_rollback`/`after_commit` callbacks and only print them to the logs.
# In the next version, these errors will no longer be suppressed.

View File

@ -0,0 +1,5 @@
class AddLocaleToUser < ActiveRecord::Migration
def change
add_column :users, :locale, :string
end
end