From 5e3f394df3a0d3e87a36114185291975fcd9271b Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sat, 1 Nov 2025 09:32:10 +0000 Subject: [PATCH] Merged r24077, r24079, r24081, r24082 and r24093 from trunk to 6.1-stable (#43379). git-svn-id: https://svn.redmine.org/redmine/branches/6.1-stable@24101 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- config/locales/en.yml | 5 ++ .../common_mark/alerts_icons_filter.rb | 6 ++ .../common_mark/alerts_icons_filter_test.rb | 67 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb diff --git a/config/locales/en.yml b/config/locales/en.yml index f67d2d2f3..d5be2883f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1171,6 +1171,11 @@ en: label_oauth_admin_access: Administration label_oauth_application_plural: Applications label_oauth_authorized_application_plural: Authorized applications + label_alert_note: Note + label_alert_tip: Tip + label_alert_warning: Warning + label_alert_caution: Caution + label_alert_important: Important button_login: Login button_submit: Submit 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 27429d778..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,6 +48,12 @@ 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 + # 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) if icon_html 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 new file mode 100644 index 000000000..43abfc5f7 --- /dev/null +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/alerts_icons_filter_test.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_relative '../../../../../test_helper' + +if Object.const_defined?(:Commonmarker) + require 'redmine/wiki_formatting/common_mark/alerts_icons_filter' + + class Redmine::WikiFormatting::CommonMark::AlertsIconsFilterTest < ActiveSupport::TestCase + include Redmine::I18n + + def format(markdown) + Redmine::WikiFormatting::CommonMark::MarkdownFilter.to_html(markdown, Redmine::WikiFormatting::CommonMark::PIPELINE_CONFIG) + end + + def filter(html) + Redmine::WikiFormatting::CommonMark::AlertsIconsFilter.to_html(html, @options) + end + + def setup + @options = { } + end + + def teardown + set_language_if_valid 'en' + end + + def test_should_render_alert_blocks_with_localized_labels + set_language_if_valid 'de' + text = <<~MD + > [!note] + > This is a note. + MD + + html = filter(format(text)) + 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