Language detection refactor (#2099)
* Extract detect_language to separate class * Use default locale, not just en * Add spec to confirm that whatlanguage cant identify empty string * Allow account locale to override default in language detector * PostStatusService supplies an account to detect language
This commit is contained in:
parent
0a7588282a
commit
297c11dba2
4 changed files with 106 additions and 3 deletions
|
@ -19,7 +19,7 @@ class PostStatusService < BaseService
|
|||
sensitive: options[:sensitive],
|
||||
spoiler_text: options[:spoiler_text] || '',
|
||||
visibility: options[:visibility],
|
||||
language: detect_language(text),
|
||||
language: detect_language_for(text, account),
|
||||
application: options[:application])
|
||||
|
||||
attach_media(status, media)
|
||||
|
@ -52,8 +52,8 @@ class PostStatusService < BaseService
|
|||
media.update(status_id: status.id)
|
||||
end
|
||||
|
||||
def detect_language(text)
|
||||
WhatLanguage.new(:all).language_iso(text) || 'en'
|
||||
def detect_language_for(text, account)
|
||||
LanguageDetector.new(text, account).to_iso_s
|
||||
end
|
||||
|
||||
def process_mentions_service
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue