function locale_string_is_safe

Same name and namespace in other branches
  1. 10 core/modules/locale/locale.module \locale_string_is_safe()
  2. 11.x core/modules/locale/locale.module \locale_string_is_safe()
  3. 9 core/modules/locale/locale.module \locale_string_is_safe()
  4. 8.9.x core/modules/locale/locale.module \locale_string_is_safe()
  5. 7.x includes/locale.inc \locale_string_is_safe()

Check that a string is safe to be added or imported as a translation.

This test can be used to detect possibly bad translation strings. It should not have any false positives. But it is only a test, not a transformation, as it destroys valid HTML. We cannot reliably filter translation strings on import because some strings are irreversibly corrupted. For example, an & in the translation would get encoded to & by \Drupal\Component\Utility\Xss::filter() before being put in the database, and thus would be displayed incorrectly.

The allowed tag list is like \Drupal\Component\Utility\Xss::filterAdmin(), but omitting div and img as not needed for translation and likely to cause layout issues (div) or a possible attack vector (img).

Deprecated

in drupal:11.5.0 and is removed from drupal:13.0.0. Use LocaleXss::stringIsSafe() instead.

See also

https://www.drupal.org/node/3616293

1 call to locale_string_is_safe()
HelpTopicsSyntaxTest::verifyTopic in core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php
Verifies rendering and standards compliance of one help topic.

File

core/modules/locale/locale.module, line 602

Code

function locale_string_is_safe($string) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use LocaleXss::stringIsSafe() instead. See https://www.drupal.org/node/3616293', E_USER_DEPRECATED);
  return LocaleXss::stringIsSafe($string);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.