mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-01 03:52:34 +00:00
20 lines
485 B
Ruby
20 lines
485 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module DiscourseAi
|
||
|
module Translation
|
||
|
class TopicLocaleDetector
|
||
|
def self.detect_locale(topic)
|
||
|
return if topic.blank?
|
||
|
|
||
|
text = topic.title.dup
|
||
|
text << " #{topic.first_post.raw}" if topic.first_post.raw
|
||
|
|
||
|
detected_locale = LanguageDetector.new(text).detect
|
||
|
locale = LocaleNormalizer.normalize_to_i18n(detected_locale)
|
||
|
topic.update_column(:locale, locale)
|
||
|
locale
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|