mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
Currently the `content_localization_language_switcher` validation error
names prerequisite settings as plain text so admins have to search for
each one manually.
This change extends the `{{setting:...}}` marker from #40338 with a
multi-setting form: `{{settings:one,two|label}}`. This renders a single
link to a filtered view of all the referenced settings.
The error message now links each required setting inline plus an "All
required settings" link. The admin UI receives an HTML message (and
plain text is still provided elsewhere, like the API).
<img width="1408" height="464" alt="image"
src="https://github.com/user-attachments/assets/576bcd79-daf1-4bd7-84ec-2add4db27f85"
/>
All settings are shown with an OR search prefixed by `any:` so
pipe-delineated settings can still be searched for separately
`any:content_localization_language_switcher|set_locale_from_cookie|allow_user_locale|content_localization_supported_locales`
<img width="2318" height="1706" alt="image"
src="https://github.com/user-attachments/assets/332092de-8d7c-4935-9e08-c3cb38a38fad"
/>
83 lines
2.7 KiB
Ruby
Vendored
83 lines
2.7 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
require "tmpdir"
|
|
|
|
load Rails.root.join("script/i18n_lint.rb")
|
|
|
|
RSpec.describe LocaleFileValidator do
|
|
def errors_for(value)
|
|
Dir.mktmpdir("i18n-lint") do |dir|
|
|
path = File.join(dir, "server.en.yml")
|
|
File.write(path, { "en" => { "test_key" => value } }.to_yaml)
|
|
|
|
validator = described_class.new(path)
|
|
validator.has_errors?
|
|
validator.instance_variable_get(:@errors)
|
|
end
|
|
end
|
|
|
|
describe "setting link markers" do
|
|
VALID_MARKERS = [
|
|
"{{setting:title}}",
|
|
"{{setting:s3_upload_bucket}}",
|
|
"{{settings:title,logo}}",
|
|
"{{settings:title,logo|All required settings}}",
|
|
"{{settings:set_locale_from_cookie,allow_user_locale,title|View them}}",
|
|
]
|
|
|
|
MALFORMED_MARKERS = [
|
|
"{{setting:Title}}", # uppercase name
|
|
"{{setting:title }}", # trailing space
|
|
"{{setting:}}", # empty name
|
|
"{{settings:title, logo|label}}", # space after comma
|
|
"{{settings:title;logo|label}}", # wrong separator
|
|
"{{settings:title,logo|}}", # empty label
|
|
"{{settings:title,logo|la|bel}}", # pipe inside label
|
|
"{{settings:title,logo|la{bel}}", # brace inside label
|
|
"{{settings:,title}}", # leading comma
|
|
"{{setting:title}", # unclosed singular marker
|
|
"{{settings:title,logo|All}", # unclosed plural marker
|
|
"{{setting:title", # no closing braces at all
|
|
]
|
|
|
|
VALID_MARKERS.each do |marker|
|
|
it "accepts #{marker}" do
|
|
errors = errors_for("Some text with #{marker} in it.")
|
|
expect(errors[:invalid_setting_link_format]).to be_empty
|
|
expect(errors[:invalid_interpolation_key_format]).to be_empty
|
|
end
|
|
end
|
|
|
|
MALFORMED_MARKERS.each do |marker|
|
|
it "flags #{marker} as malformed" do
|
|
errors = errors_for("Some text with #{marker} in it.")
|
|
expect(
|
|
errors[:invalid_setting_link_format].presence ||
|
|
errors[:invalid_interpolation_key_format].presence,
|
|
).to eq(["test_key"])
|
|
end
|
|
end
|
|
|
|
it "still flags handlebars-style interpolation that isn't a setting marker" do
|
|
expect(errors_for("Hello {{username}}!")[:invalid_interpolation_key_format]).to eq(
|
|
["test_key"],
|
|
)
|
|
end
|
|
|
|
it "accepts %{}-style interpolation untouched" do
|
|
errors = errors_for("Hello %{username}, see {{setting:title}}.")
|
|
expect(errors.values.flatten).to be_empty
|
|
end
|
|
|
|
(VALID_MARKERS + MALFORMED_MARKERS).each do |marker|
|
|
it "agrees with LabelFormatter about #{marker}" do
|
|
text = "Some text with #{marker} in it."
|
|
|
|
lint_accepts = errors_for(text).values.flatten.empty?
|
|
formatter_expands = SiteSettings::LabelFormatter.expand_setting_links(text) != text
|
|
|
|
expect(lint_accepts).to eq(formatter_expands)
|
|
end
|
|
end
|
|
end
|
|
end
|