mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
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
18 lines
445 B
Ruby
Vendored
18 lines
445 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PostLocaleUpdater
|
|
def self.update(post:, locale:, user:)
|
|
Guardian.new(user).ensure_can_localize_post!(post)
|
|
validate_locale!(locale)
|
|
|
|
post.update!(locale:)
|
|
post
|
|
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
|