mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +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" />
184 lines
5.4 KiB
Ruby
Vendored
184 lines
5.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe Admin::Config::AboutController do
|
|
fab!(:admin)
|
|
fab!(:moderator)
|
|
|
|
before do
|
|
sign_in(admin)
|
|
SiteSetting.content_localization_enabled = true
|
|
SiteSetting.content_localization_supported_locales = "ja|pt_BR"
|
|
end
|
|
|
|
describe "#localizations" do
|
|
it "returns localizations for the requested locale" do
|
|
SiteSettingLocalization.create!(setting_name: "title", locale: "ja", value: "日本語タイトル")
|
|
SiteSettingLocalization.create!(
|
|
setting_name: "site_description",
|
|
locale: "pt_BR",
|
|
value: "Descrição",
|
|
)
|
|
|
|
get "/admin/config/about/localizations.json", params: { locale: "ja" }
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body).to eq(
|
|
"locale" => "ja",
|
|
"localizations" => {
|
|
"title" => {
|
|
"value" => "日本語タイトル",
|
|
"cooked" => nil,
|
|
},
|
|
},
|
|
)
|
|
end
|
|
|
|
it "does not return blank localizations" do
|
|
localization =
|
|
SiteSettingLocalization.create!(setting_name: "title", locale: "ja", value: "日本語タイトル")
|
|
localization.update_column(:value, "")
|
|
|
|
get "/admin/config/about/localizations.json", params: { locale: "ja" }
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body["localizations"]).to be_empty
|
|
end
|
|
|
|
it "normalizes hyphenated locale names" do
|
|
get "/admin/config/about/localizations.json", params: { locale: "pt-BR" }
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body["locale"]).to eq("pt_BR")
|
|
end
|
|
|
|
it "rejects the site default locale" do
|
|
SiteSetting.default_locale = "en"
|
|
|
|
get "/admin/config/about/localizations.json", params: { locale: "en" }
|
|
|
|
expect(response.status).to eq(400)
|
|
end
|
|
|
|
it "rejects requests when content localization is disabled" do
|
|
SiteSetting.content_localization_enabled = false
|
|
|
|
get "/admin/config/about/localizations.json", params: { locale: "ja" }
|
|
|
|
expect(response.status).to eq(403)
|
|
end
|
|
|
|
it "rejects moderators" do
|
|
sign_in(moderator)
|
|
|
|
get "/admin/config/about/localizations.json", params: { locale: "ja" }
|
|
|
|
expect(response.status).to eq(404)
|
|
end
|
|
end
|
|
|
|
describe "#update_localizations" do
|
|
it "saves localized about settings and logs the change" do
|
|
put "/admin/config/about/localizations.json",
|
|
params: {
|
|
locale: "ja",
|
|
general_settings: {
|
|
name: "日本語タイトル",
|
|
summary: "日本語の説明",
|
|
extended_description: "日本語の **詳細** 説明",
|
|
about_banner_image: "/ignored.png",
|
|
},
|
|
contact_information: {
|
|
community_owner: "日本語の所有者",
|
|
contact_email: "ignored@example.com",
|
|
},
|
|
your_organization: {
|
|
company_name: "日本語会社",
|
|
company_url: "https://example.com/ja",
|
|
governing_law: "日本法",
|
|
city_for_disputes: "東京",
|
|
},
|
|
}
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body.dig("localizations", "title", "value")).to eq("日本語タイトル")
|
|
expect(
|
|
response.parsed_body.dig("localizations", "extended_site_description", "cooked"),
|
|
).to include("<strong>詳細</strong>")
|
|
|
|
expect(response.parsed_body["localizations"].keys).to contain_exactly(
|
|
"extended_site_description",
|
|
"site_description",
|
|
"title",
|
|
)
|
|
|
|
staff_action_log = UserHistory.where(action: UserHistory.actions[:custom_staff]).last
|
|
|
|
aggregate_failures do
|
|
expect(staff_action_log.custom_type).to eq("update_site_setting_localizations")
|
|
expect(staff_action_log.details).to include("locale: ja")
|
|
expect(staff_action_log.details).to include(
|
|
"setting_names: extended_site_description|site_description|title",
|
|
)
|
|
end
|
|
end
|
|
|
|
it "removes a localization when the value is blank" do
|
|
SiteSettingLocalization.create!(
|
|
setting_name: "site_description",
|
|
locale: "ja",
|
|
value: "日本語の説明",
|
|
)
|
|
|
|
put "/admin/config/about/localizations.json",
|
|
params: {
|
|
locale: "ja",
|
|
general_settings: {
|
|
summary: "",
|
|
},
|
|
}
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body["localizations"]).to be_empty
|
|
end
|
|
|
|
it "rejects unsupported locales" do
|
|
put "/admin/config/about/localizations.json",
|
|
params: {
|
|
locale: "de",
|
|
general_settings: {
|
|
name: "Deutsch",
|
|
},
|
|
}
|
|
|
|
expect(response.status).to eq(400)
|
|
end
|
|
|
|
it "rejects updates when content localization is disabled" do
|
|
SiteSetting.content_localization_enabled = false
|
|
|
|
put "/admin/config/about/localizations.json",
|
|
params: {
|
|
locale: "ja",
|
|
general_settings: {
|
|
name: "日本語タイトル",
|
|
},
|
|
}
|
|
|
|
expect(response.status).to eq(403)
|
|
end
|
|
|
|
it "rejects moderator updates" do
|
|
sign_in(moderator)
|
|
|
|
put "/admin/config/about/localizations.json",
|
|
params: {
|
|
locale: "ja",
|
|
general_settings: {
|
|
name: "日本語タイトル",
|
|
},
|
|
}
|
|
|
|
expect(response.status).to eq(404)
|
|
end
|
|
end
|
|
end
|