From 52890707c51152a6b1ad6c1c87cef691104d4e5a Mon Sep 17 00:00:00 2001
From: Yuki <aaron.ahmed.eve@gmail.com>
Date: Wed, 27 May 2015 06:51:06 +0530
Subject: [PATCH 1/4] less logic in views

---
 app/helpers/application_helper.rb     | 8 ++++----
 app/views/shared/_answerbox.html.haml | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 74fe977f..56f90b2d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -43,10 +43,10 @@ module ApplicationHelper
     content_tag(:span, body, {title: tooltip_content, "data-toggle" => "tooltip", "data-placement" => placement} )
   end
 
-  def time_tooltip(question, placement = "bottom")
-    t = tooltip time_ago_in_words(question.created_at), localize(question.created_at), placement
-    unless question.user.nil? or question.author_is_anonymous
-      t = content_tag(:a, t, {href: show_user_question_path(question.user.screen_name, question.id)})
+  def time_tooltip(subject, placement = "bottom")
+    t = tooltip time_ago_in_words(subject.created_at), localize(subject.created_at), placement
+    unless subject.user.nil? or (subject.respond_to?(:author_is_anonymous) and subject.author_is_anonymous)
+      t = content_tag(:a, t, {href: show_user_question_path(subject.user.screen_name, subject.id)})
     end
     t
   end
diff --git a/app/views/shared/_answerbox.html.haml b/app/views/shared/_answerbox.html.haml
index 605d8df1..880d42d3 100644
--- a/app/views/shared/_answerbox.html.haml
+++ b/app/views/shared/_answerbox.html.haml
@@ -54,14 +54,14 @@
               %h6.media-heading.answerbox--answer-user
                 = raw t('views.answerbox.answered', hide: hidespan(t('views.answerbox.hide'), "xs"), user: user_screen_name(a.user))
               .answerbox--answer-date
-                = link_to((raw t('views.answerbox.time', time: tooltip(time_ago_in_words(a.created_at), a.created_at, "bottom"))), show_user_answer_path(a.user.screen_name, a.id))
+                = link_to(raw(t('views.answerbox.time', time: time_tooltip(a))))
         .col-md-6.col-sm-8.col-xs-6.text-right
           = render 'shared/answerbox_buttons', a: a
     - else
       .row
         .col-md-6.col-sm-4.col-xs-6.text-left.text-muted
           %i.fa.fa-clock-o
-          = link_to((raw t('views.answerbox.time', time: tooltip(time_ago_in_words(a.created_at), a.created_at, "bottom"))), show_user_answer_path(a.user.screen_name, a.id))
+            = link_to(raw(t('views.answerbox.time', time: time_tooltip(a))))
         .col-md-6.col-sm-8.col-xs-6.text-right
           = render 'shared/answerbox_buttons', a: a
   .panel-footer{id: "ab-comments-section-#{a.id}", style: @display_all.nil? ? 'display: none' : nil }

From 50e1186e7937c680c4cf3f17f01dc94a0917bc32 Mon Sep 17 00:00:00 2001
From: Yuki <aaron.ahmed.eve@gmail.com>
Date: Wed, 27 May 2015 07:06:18 +0530
Subject: [PATCH 2/4] Accept-Language header support

---
 Gemfile                                   | 1 +
 app/controllers/application_controller.rb | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/Gemfile b/Gemfile
index d285b9a9..78211c86 100644
--- a/Gemfile
+++ b/Gemfile
@@ -39,6 +39,7 @@ gem 'fog'
 gem 'fog-aws'
 gem 'momentjs-rails', '>= 2.9.0'
 gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14'
+gem 'http_accept_language'
 
 gem 'ruby-progressbar'
 
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index aae3e36e..09191790 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -14,6 +14,8 @@ class ApplicationController < ActionController::Base
         I18n.locale = current_user.locale
       elsif not cookies[:hl].nil?
         I18n.locale = cookies[:hl]
+      elsif not http_accept_language.user_preferred_languages.length > 0
+        I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) or "en"
       end
     else
       I18n.locale = params[:hl]

From ff693d9b937e36e4d7af3fb44b62ba9d273b39a2 Mon Sep 17 00:00:00 2001
From: Yuki <aaron.ahmed.eve@gmail.com>
Date: Wed, 27 May 2015 07:07:39 +0530
Subject: [PATCH 3/4] [skip ci] duplicate gem

---
 Gemfile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Gemfile b/Gemfile
index 78211c86..d285b9a9 100644
--- a/Gemfile
+++ b/Gemfile
@@ -39,7 +39,6 @@ gem 'fog'
 gem 'fog-aws'
 gem 'momentjs-rails', '>= 2.9.0'
 gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14'
-gem 'http_accept_language'
 
 gem 'ruby-progressbar'
 

From eda3bf5e62ce9451e6c78fefc14b788b1e5e4fc9 Mon Sep 17 00:00:00 2001
From: Yuki <aaron.ahmed.eve@gmail.com>
Date: Wed, 27 May 2015 07:13:33 +0530
Subject: [PATCH 4/4] Don't raise on invalid locales

---
 config/application.rb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/config/application.rb b/config/application.rb
index 27bbe789..9d5f6122 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -26,6 +26,8 @@ module Justask
 
     config.i18n.default_locale = "en"
     config.i18n.fallbacks = true
+    config.i18n.enforce_available_locales = false
+
 
     # DEPRECATION WARNING: Currently, Active Record suppresses errors raised
     # within `after_rollback`/`after_commit` callbacks and only print them to the logs.