From b6d7726ecbc833abd00f6a9d36b24d9776cfe623 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 8 Feb 2022 02:41:17 +0100 Subject: Remove language detection through cld3 (#17478) * Remove language detection through cld3 * Update app/helpers/languages_helper.rb Co-authored-by: Yamagishi Kazutoshi Co-authored-by: Yamagishi Kazutoshi --- app/services/activitypub/process_status_update_service.rb | 6 +----- app/services/post_status_service.rb | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'app/services') diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index 977928127..b1cea1cdf 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -120,7 +120,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService @status.text = @status_parser.text || '' @status.spoiler_text = @status_parser.spoiler_text || '' @status.sensitive = @account.sensitized? || @status_parser.sensitive || false - @status.language = @status_parser.language || detected_language + @status.language = @status_parser.language @status.edited_at = @status_parser.edited_at || Time.now.utc if significant_changes? @status.save! @@ -210,10 +210,6 @@ class ActivityPub::ProcessStatusUpdateService < BaseService { redis: Redis.current, key: "create:#{@uri}", autorelease: 15.minutes.seconds } end - def detected_language - LanguageDetector.instance.detect(@status_parser.text, @account) - end - def create_previous_edit! # We only need to create a previous edit when no previous edits exist, e.g. # when the status has never been edited. For other cases, we always create diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 294ae43eb..b3bc4a0a2 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -2,6 +2,7 @@ class PostStatusService < BaseService include Redisable + include LanguagesHelper MIN_SCHEDULE_OFFSET = 5.minutes.freeze @@ -109,10 +110,6 @@ class PostStatusService < BaseService raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if @media.any?(&:not_processed?) end - def language_from_option(str) - ISO_639.find(str)&.alpha2 - end - def process_mentions_service ProcessMentionsService.new end @@ -165,7 +162,7 @@ class PostStatusService < BaseService sensitive: @sensitive, spoiler_text: @options[:spoiler_text] || '', visibility: @visibility, - language: language_from_option(@options[:language]) || @account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(@text, @account), + language: valid_locale_or_nil(@options[:language].presence || @account.user&.preferred_posting_language || I18n.default_locale), application: @options[:application], rate_limit: @options[:with_rate_limit], }.compact -- cgit