about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-04-21 22:26:25 -0400
committerEugen <eugen@zeonfederated.com>2017-04-22 04:26:25 +0200
commit629d35e6f5d353d30661c1af7bbcc8aa6411e698 (patch)
treebbe02c15e82b7087eab38f9043ab2947607e1c5f /app
parent67dea31b0f83eb711bbd49a7b893d04ca16c56fa (diff)
[WIP] Html lang on statuses (#2297)
* Add html lang attributes around statuses

* Remove urls from language detection
Diffstat (limited to 'app')
-rw-r--r--app/lib/language_detector.rb10
-rw-r--r--app/views/stream_entries/_detailed_status.html.haml2
-rw-r--r--app/views/stream_entries/_simple_status.html.haml2
3 files changed, 11 insertions, 3 deletions
diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb
index b6f81923b..9a32d6a64 100644
--- a/app/lib/language_detector.rb
+++ b/app/lib/language_detector.rb
@@ -9,11 +9,19 @@ class LanguageDetector
   end
 
   def to_iso_s
-    WhatLanguage.new(:all).language_iso(text) || default_locale.to_sym
+    WhatLanguage.new(:all).language_iso(text_without_urls) || default_locale.to_sym
   end
 
   private
 
+  def text_without_urls
+    text.dup.tap do |new_text|
+      URI.extract(new_text).each do |url|
+        new_text.gsub!(url, '')
+      end
+    end
+  end
+
   def default_locale
     account&.user&.locale || I18n.default_locale
   end
diff --git a/app/views/stream_entries/_detailed_status.html.haml b/app/views/stream_entries/_detailed_status.html.haml
index 626b97f41..0b4eeba54 100644
--- a/app/views/stream_entries/_detailed_status.html.haml
+++ b/app/views/stream_entries/_detailed_status.html.haml
@@ -12,7 +12,7 @@
       %p{ style: 'margin-bottom: 0' }<
         %span.p-summary>= "#{status.spoiler_text} "
         %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
-    %div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
+    %div.e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
 
 
   - unless status.media_attachments.empty?
diff --git a/app/views/stream_entries/_simple_status.html.haml b/app/views/stream_entries/_simple_status.html.haml
index 52518bc33..99acae23d 100644
--- a/app/views/stream_entries/_simple_status.html.haml
+++ b/app/views/stream_entries/_simple_status.html.haml
@@ -17,7 +17,7 @@
       %p{ style: 'margin-bottom: 0' }<
         %span.p-summary>= "#{status.spoiler_text} "
         %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
-    %div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
+    %div.e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
 
   - unless status.media_attachments.empty?
     .status__attachments