mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 02:05:37 +08:00
This commit improves the prompt, and also matches the return value against this: - https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.1 - **Primary Language Subtag**: ... Two-character primary language subtags were defined in the IANA registry according to the assignments found in the standard "ISO 639-1:2002 ... - **Extended Language Subtags**: ... Extended language subtags consist solely of three-letter subtags. This commit also moves examples into its own Meta: https://meta.discourse.org/t/locale-detector-return-value-issues/381852
18 lines
447 B
Ruby
Vendored
18 lines
447 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Translation
|
|
class TopicLocaleDetector
|
|
def self.detect_locale(topic)
|
|
return if topic.blank?
|
|
|
|
detected_locale = LanguageDetector.new(topic.title.dup, topic:).detect
|
|
return if detected_locale.blank?
|
|
|
|
locale = LocaleNormalizer.normalize_to_i18n(detected_locale)
|
|
topic.update_column(:locale, locale)
|
|
locale
|
|
end
|
|
end
|
|
end
|
|
end
|