Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How to reproduce
* create a rule that translates a text with HTML
* see that html is treated as plain text
The rule below prints
* one message with link (as expected)
* one message with check-plain'ed html
This makes translation unusable in many use cases so prioritizing high.
{ "rules_test_translation" : {
"LABEL" : "TEST translation",
"PLUGIN" : "action set",
"OWNER" : "rules",
"REQUIRES" : [ "rules_i18n", "rules" ],
"ACTION SET" : [
{ "drupal_message" : { "message" : "Message with \u003Ca href=\u0022\/user\u0022\u003Elink\u003C\/a\u003E" } },
{ "rules_i18n_t" : {
"USING" : {
"text" : "Message with \u003Ca href=\u0022\/user\u0022\u003Elink\u003C\/a\u003E",
"language" : [ "site:current-page:language" ]
},
"PROVIDE" : { "text" : { "message_translated" : "Message translated" } }
}
},
{ "drupal_message" : { "message" : [ "message-translated" ] } }
]
}
}
Comments
Comment #1
geek-merlinComment #2
TR CreditAttribution: TR commentedThis is not a problem with the "Translate a text" action - debugging shows that the translate action DOES return the markup as desired. Likewise, it's not a problem with the "Show a message on the site" action - that action shows markup properly IF provided with markup.
Instead, the problem seems to be that "provided" text variables, like "message_translated" above, are always run through check_plain() to sanitize them. (This happens on line 968 of includes/rules.core.inc, if you're interested ...).
A solution needs to be careful and not just remove the check_plain() for all provided text variables. The hook_rules_action_info() should be able to turn off sanitation for specific provided variables, but the 'sanitize' flag doesn't currently seem to work for provided variables ...