From 19927b2382f0fc3875bf51562b46950be6555df9 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Fri, 31 Oct 2025 06:32:31 +0000 Subject: [PATCH] Localize default commonmark alert titles (#43379). Patch by Go MAEDA (user:maeda) and Marius BALTEANU (user:marius.balteanu). git-svn-id: https://svn.redmine.org/redmine/trunk@24093 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../common_mark/alerts_icons_filter.rb | 7 +++++-- .../common_mark/alerts_icons_filter_test.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb b/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb index 73a09b15f..595c6cf58 100644 --- a/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb +++ b/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb @@ -48,8 +48,11 @@ module Redmine icon_name = ALERT_TYPE_TO_ICON_NAME[alert_type] next unless icon_name # Skip if no specific icon is defined for this alert type - # label alert translation - node.content = ::I18n.t("label_alert_#{alert_type}", default: node.content) + # Translate the alert title only if it matches a known alert type + # (i.e., the title has not been overridden) + if ALERT_TYPE_TO_ICON_NAME.key?(node.content.downcase) + node.content = ::I18n.t("label_alert_#{alert_type}", default: node.content) + end icon_html = ApplicationController.helpers.sprite_icon(icon_name, node.text) diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb index 099c7a486..43abfc5f7 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb @@ -52,5 +52,16 @@ if Object.const_defined?(:Commonmarker) expected = %r{#{I18n.t('label_alert_note')}} assert_match expected, html end + + def test_should_not_translate_title_if_overridden + set_language_if_valid 'de' + text = <<~MD + > [!note] Custom Note Title + > This is a note. + MD + html = filter(format(text)) + assert_match %r{Custom Note Title}, html + end + end end