diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index beed49fb..a3bf4c5e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 4f627bb4..27bbe789 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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. diff --git a/db/migrate/20150526031159_add_locale_to_user.rb b/db/migrate/20150526031159_add_locale_to_user.rb new file mode 100644 index 00000000..fdea9cfd --- /dev/null +++ b/db/migrate/20150526031159_add_locale_to_user.rb @@ -0,0 +1,5 @@ +class AddLocaleToUser < ActiveRecord::Migration + def change + add_column :users, :locale, :string + end +end