diff options
author | Eugen <eugen@zeonfederated.com> | 2017-04-16 20:32:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-16 20:32:17 +0200 |
commit | e4af4898de8ab962bf39ced5d31d88e3fd510538 (patch) | |
tree | 7853ee0cf1ee9c2bd0cf22802af9adcf0efed547 /app | |
parent | 6d70a8026309c2d41e2402ec84875ced8e181105 (diff) |
Add language detection (#1772)
* Add language detection via WhatLanguage and (de)serialization of it through Atom * Fix default language in ProcessFeedService * Re-add newline before 'react-rails' Gem to fix groupings Fixes Code Climate issue
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/atom_serializer.rb | 4 | ||||
-rw-r--r-- | app/services/post_status_service.rb | 5 | ||||
-rw-r--r-- | app/services/process_feed_service.rb | 5 |
3 files changed, 12 insertions, 2 deletions
diff --git a/app/lib/atom_serializer.rb b/app/lib/atom_serializer.rb index 180b9bb82..6f1910440 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/atom_serializer.rb @@ -327,8 +327,8 @@ class AtomSerializer end def serialize_status_attributes(entry, status) - append_element(entry, 'summary', status.spoiler_text) if status.spoiler_text? - append_element(entry, 'content', Formatter.instance.format(status.proper).to_str, type: 'html') + append_element(entry, 'summary', status.spoiler_text, 'xml:lang': status.language) if status.spoiler_text? + append_element(entry, 'content', Formatter.instance.format(status.proper).to_str, type: 'html', 'xml:lang': status.language) status.mentions.each do |mentioned| append_element(entry, 'link', nil, rel: :mentioned, 'ostatus:object-type': TagManager::TYPES[:person], href: TagManager.instance.uri_for(mentioned.account)) diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 221aa42a3..d8202bea8 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -19,6 +19,7 @@ class PostStatusService < BaseService sensitive: options[:sensitive], spoiler_text: options[:spoiler_text] || '', visibility: options[:visibility], + language: detect_language(text), application: options[:application]) attach_media(status, media) @@ -51,6 +52,10 @@ class PostStatusService < BaseService media.update(status_id: status.id) end + def detect_language(text) + WhatLanguage.new(:all).language_iso(text) + end + def process_mentions_service @process_mentions_service ||= ProcessMentionsService.new end diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index 64a531e74..98d92f630 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -119,6 +119,7 @@ class ProcessFeedService < BaseService spoiler_text: content_warning(entry), created_at: published(entry), reply: thread?(entry), + language: content_language(entry), visibility: visibility_scope(entry) ) @@ -238,6 +239,10 @@ class ProcessFeedService < BaseService xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content end + def content_language(xml = @xml) + xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['xml:lang']&.presence || 'en' + end + def content_warning(xml = @xml) xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || '' end |