discourse/lib/validators/content_localization_locales_validator.rb
Natalie Tay b20d6792bf
FEATURE: Add a hidden setting to limit number of content localization locales (#33378)
We want to add a hidden limit to the number of locales an admin can set
for localization. This is a safe limit to prevent excessive localization
(if each post can be localized to 10 locales, that's 10x the amount of
storage and tokens needed).


t/157677
2025-06-30 15:29:58 +08:00

20 lines
446 B
Ruby

# frozen_string_literal: true
class ContentLocalizationLocalesValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(val)
return true if val == ""
count = val.split("|").length
SiteSetting.content_localization_max_locales >= count
end
def error_message
I18n.t(
"site_settings.errors.content_localization_locale_limit",
max: SiteSetting.content_localization_max_locales,
)
end
end