0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/lib/topic_locale_updater.rb
Natalie Tay cb739f7f2d
UX: Allow user to set post and topic title language when manually creating post translations in modal (#41734)
Related:
https://meta.discourse.org/t/manual-localization-doesnt-seem-to-be-working/407319

Users have gotten tripped over and over again when manually inserting
translations for posts, not knowing they need to set the post language
first before the translation is shown (explained
[here](https://meta.discourse.org/t/manual-localization-doesnt-seem-to-be-working/407319/7?u=nat)).

This PR adds the ability to allow the user to set the post language in
the modal when they are working with translations, highlighting the fact
that they need to set the post language before translations can be shown
2026-07-16 10:43:39 +08:00

18 lines
451 B
Ruby
Vendored

# frozen_string_literal: true
class TopicLocaleUpdater
def self.update(topic:, locale:, user:)
Guardian.new(user).ensure_can_localize_topic!(topic)
validate_locale!(locale)
topic.update!(locale:)
topic
end
def self.validate_locale!(locale)
return if locale.nil? || LocaleSiteSetting.supported_locales.include?(locale)
raise Discourse::InvalidParameters.new(:locale)
end
private_class_method :validate_locale!
end