Same name in other branches
- 6.0.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::translateCallback()
- 8.x-3.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::translateCallback()
- 8.x-4.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::translateCallback()
Run preg matches through the t() function.
Paramètres
array $matches: Array of matches from preg_replace_callback().
Return value
string Replaced string.
Fichier
-
advagg_mod/
src/ Asset/ TranslateCss.php, line 56
Classe
- TranslateCss
- Applies the t() function to strings in CSS assets.
Namespace
Drupal\advagg_mod\AssetCode
protected function translateCallback(array $matches) {
// Skip if equal to ; or }.
if ($matches[1] === ';' || $matches[1] === '}') {
return $matches[0];
}
// Remove quotes for t function.
$before = substr($matches[1], 1, -1);
// Only run if it contains A-Za-z.
if (!preg_match('/[A-Za-z]/', $before)) {
return $matches[0];
}
// Only run if it contains characters other than unicode.
$css_unicode_pattern = '/\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|[ \\t\\r\\n\\f])?/';
$unicode_removed = preg_replace($css_unicode_pattern, '', $before);
if (empty($unicode_removed)) {
return $matches[0];
}
// Run t function and put back into string.
return str_replace($before, (string) $this->t('@before', [
'@before' => $before,
]), $matches[0]);
}