DEV: Site setting keyword changes (#29486)

This commit contains two changes to how our site setting
keyword system works:

1. Crowdin, our translation provider, does not support YAML lists,
   so we are changing site setting keywords in server.en.yml to
   be pipe-separated (|)
2. It's unclear to translators what they are supposed to do with
   aliases of site settings where the name has changed, e.g.
   min_trust_level_for_here_mention. Instead of getting these as
   keywords from the yml file, we can discern these from
   SiteSettings::DeprecatedSettings automatically, and still use
   them for client-side search

These changes should help improve the situation for translators.
This commit is contained in:
Martin Brennan 2024-10-31 13:18:34 +10:00 committed by GitHub
parent 1c717f733c
commit d5b328b193
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 36 deletions

View File

@ -2805,41 +2805,9 @@ en:
invalid_search_ranking_weights: "Value is invalid for search_ranking_weights site setting. Example: '{0.1,0.2,0.3,1.0}'. Note that maximum value for each weight is 1.0." invalid_search_ranking_weights: "Value is invalid for search_ranking_weights site setting. Example: '{0.1,0.2,0.3,1.0}'. Note that maximum value for each weight is 1.0."
keywords: keywords:
anonymous_posting_allowed_groups: "anonymous_posting_min_trust_level" clean_up_inactive_users_after_days: "deactivated|inactive|unactivated"
here_mention_allowed_groups: "min_trust_level_for_here_mention" purge_unactivated_users_grace_period_days: "deactivated|inactive|unactivated"
shared_drafts_allowed_groups: "shared_drafts_min_trust_level" navigation_menu: "sidebar|header dropdown"
approve_unless_allowed_groups: "approve_unless_trust_level"
approve_new_topics_unless_allowed_groups: "approve_new_topics_unless_trust_level"
email_in_allowed_groups: "email_in_min_trust"
edit_wiki_post_allowed_groups: "min_trust_to_edit_wiki_post"
uploaded_avatars_allowed_groups: "allow_uploaded_avatars"
create_topic_allowed_groups: "min_trust_to_create_topic"
edit_post_allowed_groups: "min_trust_to_edit_post"
flag_post_allowed_groups: "min_trust_to_flag_posts"
delete_all_posts_and_topics_allowed_groups: "tl4_delete_posts_and_topics"
user_card_background_allowed_groups: "min_trust_level_to_allow_user_card_background"
invite_allowed_groups: "min_trust_level_to_allow_invite"
ignore_allowed_groups: "min_trust_level_to_allow_ignore"
self_wiki_allowed_groups: "min_trust_to_allow_self_wiki"
create_tag_allowed_groups: "min_trust_to_create_tag"
send_email_messages_allowed_groups: "min_trust_to_send_email_messages"
skip_review_media_groups: "review_media_unless_trust_level"
embedded_media_allowed_groups: "min_trust_to_post_embedded_media"
post_links_allowed_groups: "min_trust_to_post_links"
user_api_key_allowed_groups: "min_trust_level_for_user_api_key"
tag_topic_allowed_groups: "min_trust_level_to_tag_topics"
profile_background_allowed_groups: "min_trust_level_to_allow_profile_background"
clean_up_inactive_users_after_days:
- "deactivated"
- "inactive"
- "unactivated"
purge_unactivated_users_grace_period_days:
- "deactivated"
- "inactive"
- "unactivated"
navigation_menu:
- "sidebar"
- "header dropdown"
placeholder: placeholder:
discourse_connect_provider_secrets: discourse_connect_provider_secrets:

View File

@ -143,6 +143,12 @@ module SiteSettingExtension
@deprecated_settings ||= SiteSettings::DeprecatedSettings::SETTINGS.map(&:first).to_set @deprecated_settings ||= SiteSettings::DeprecatedSettings::SETTINGS.map(&:first).to_set
end end
def deprecated_setting_alias(setting_name)
SiteSettings::DeprecatedSettings::SETTINGS
.find { |setting| setting.second.to_s == setting_name.to_s }
&.first
end
def settings_hash def settings_hash
result = {} result = {}
@ -302,7 +308,29 @@ module SiteSettingExtension
end end
def keywords(setting) def keywords(setting)
Array.wrap(I18n.t("site_settings.keywords.#{setting}", default: "")) translated_keywords = I18n.t("site_settings.keywords.#{setting}", default: "")
english_translated_keywords = []
if I18n.locale != :en
english_translated_keywords =
I18n.t("site_settings.keywords.#{setting}", default: "", locale: :en).split("|")
end
# TODO (martin) We can remove this workaround of checking if
# we get an array back once keyword translations in languages other
# than English have been updated not to use YAML arrays.
if translated_keywords.is_a?(Array)
return(
(
translated_keywords + [deprecated_setting_alias(setting)] + english_translated_keywords
).compact
)
end
translated_keywords
.split("|")
.concat([deprecated_setting_alias(setting)] + english_translated_keywords)
.compact
end end
def placeholder(setting) def placeholder(setting)

View File

@ -1026,4 +1026,34 @@ RSpec.describe SiteSettingExtension do
expect(SiteSetting.exclude_rel_nofollow_domains_map).to eq([]) expect(SiteSetting.exclude_rel_nofollow_domains_map).to eq([])
end end
end end
describe "keywords" do
it "gets the list of I18n keywords for the setting" do
expect(SiteSetting.keywords(:clean_up_inactive_users_after_days)).to eq(
I18n.t("site_settings.keywords.clean_up_inactive_users_after_days").split("|"),
)
end
it "gets the current locale keywords and the english keywords for the setting" do
I18n.locale = :de
expect(SiteSetting.keywords(:clean_up_inactive_users_after_days)).to match_array(
(
I18n.t("site_settings.keywords.clean_up_inactive_users_after_days").split("|") +
I18n.t("site_settings.keywords.clean_up_inactive_users_after_days", locale: :en).split(
"|",
)
).flatten,
)
end
context "when a setting also has an alias after renaming" do
before { SiteSetting.stubs(:deprecated_setting_alias).returns("some_old_setting") }
it "is included with the keywords" do
expect(SiteSetting.keywords(:clean_up_inactive_users_after_days)).to include(
"some_old_setting",
)
end
end
end
end end