mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 03:39:06 +08:00
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
20 lines
446 B
Ruby
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
|