mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-07 23:12:34 +00:00
20 lines
503 B
Ruby
20 lines
503 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module DiscourseAi
|
||
|
module Translation
|
||
|
class CategoryLocaleDetector
|
||
|
def self.detect_locale(category)
|
||
|
return if category.blank?
|
||
|
|
||
|
text = [category.name, category.description].compact.join("\n\n")
|
||
|
return if text.blank?
|
||
|
|
||
|
detected_locale = LanguageDetector.new(text).detect
|
||
|
locale = LocaleNormalizer.normalize_to_i18n(detected_locale)
|
||
|
category.update_column(:locale, locale)
|
||
|
locale
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|