mirror of
https://github.com/discourse/discourse.git
synced 2026-08-07 13:19:19 +08:00
The /about page (unlike /guidelines or /tos) is not backed by a topic, but instead via a bunch of site settings. If it were backed by a topic, localization would be easy as it can just use TopicLocalizations. We also can't swap it out to use a topic, since there are so many fields on the about page that can't be safely contained in a topic. ---------- This PR adds SiteSettingLocalization, allowing new attributes in site settings config for localization. For now this is wired into the About page settings flow: - admins can select a non-default locale on /admin/config/about - only translatable About fields are shown for that locale - localized About values are used on /about and /about.json - company_url can be set manually per locale, but is excluded from automatic translation - ~~AI backfill can translate eligible site setting localizations~~ no backfill (added in https://github.com/discourse/discourse/pull/41123/commits/386c655d2f44aca54440c069bd06ea8007793d84, removed in https://github.com/discourse/discourse/pull/41123/commits/6f8ec9cc43dca4195bda638b1ce980eb68a59941. about page has very non automa-ble fields This intentionally keeps the scope narrow. It does not make every site setting localizable, and any other setting can be localized by adding to that allowlist. Some screenshots |page | 📸 | |--|--| | eng setting | <img width="1278" height="871" alt="Screenshot 2026-06-23 at 11 00 34 PM" src="https://github.com/user-attachments/assets/59431464-fb05-41d9-8c4f-fd9aae7fb45f" /> | ja setting | <img width="1278" height="871" alt="Screenshot 2026-06-23 at 11 01 20 PM" src="https://github.com/user-attachments/assets/73cd2878-f59a-4dc4-a76d-2f46b74a6eed" /> | ja anon about page | <img width="1278" height="871" alt="Screenshot 2026-06-23 at 11 01 48 PM" src="https://github.com/user-attachments/assets/02464a5f-9ca0-4519-9521-be41498c1967" />
77 lines
2.1 KiB
Ruby
Vendored
77 lines
2.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class SiteSettingLocalizations::AboutConfig::Update
|
|
include Service::Base
|
|
|
|
params do
|
|
attribute :locale, :string
|
|
attribute :general_settings, default: -> { {} }
|
|
|
|
before_validation { self.locale = SiteSettingLocalization.normalize_locale(locale) }
|
|
|
|
validates :locale, presence: true
|
|
end
|
|
|
|
policy :can_localize_site_settings
|
|
policy :locale_is_supported
|
|
step :extract_submitted_settings
|
|
|
|
transaction do
|
|
each :submitted_settings, as: :submitted_setting do
|
|
step :save_submitted_setting
|
|
end
|
|
end
|
|
|
|
only_if(:submitted_settings_present) { step :log_update }
|
|
|
|
step :build_payload
|
|
|
|
private
|
|
|
|
def can_localize_site_settings(guardian:)
|
|
guardian.can_localize_site_settings?
|
|
end
|
|
|
|
def locale_is_supported(params:)
|
|
SiteSettingLocalization.supported_content_locale?(params.locale)
|
|
end
|
|
|
|
def extract_submitted_settings(params:)
|
|
context[:submitted_settings] = SiteSettingLocalization.about_config_settings_from_params(
|
|
params.raw_attributes,
|
|
)
|
|
end
|
|
|
|
def save_submitted_setting(guardian:, params:, submitted_setting:)
|
|
if submitted_setting[:value].blank?
|
|
SiteSettingLocalization.where(
|
|
setting_name: submitted_setting[:setting_name],
|
|
locale: params.locale,
|
|
).destroy_all
|
|
else
|
|
localization =
|
|
SiteSettingLocalization.find_or_initialize_by(
|
|
setting_name: submitted_setting[:setting_name],
|
|
locale: params.locale,
|
|
)
|
|
localization.value = submitted_setting[:value]
|
|
localization.localizer_user_id = guardian.user.id
|
|
localization.save!
|
|
end
|
|
end
|
|
|
|
def submitted_settings_present(submitted_settings:)
|
|
submitted_settings.present?
|
|
end
|
|
|
|
def log_update(guardian:, params:, submitted_settings:)
|
|
StaffActionLogger.new(guardian.user).log_update_site_setting_localizations(
|
|
locale: params.locale,
|
|
setting_names: submitted_settings.map { |setting| setting[:setting_name] },
|
|
)
|
|
end
|
|
|
|
def build_payload(params:)
|
|
context[:payload] = SiteSettingLocalization.about_config_payload(params.locale)
|
|
end
|
|
end
|