/**
* Transliterate function
*
* This method processes a string and replaces all accented UTF-8 characters by unaccented
* ASCII-7 "equivalents".
*
* @param string $string The string to transliterate.
*
* @return string The transliteration of the string.
*
* @since 1.7.0
*/
public function transliterate($string)
{
// First check for transliterator provided by translation
if ($this->transliterator !== null) {
$string = \call_user_func($this->transliterator, $string);
// Check if all symbols were transliterated (contains only ASCII), otherwise continue
if (!preg_match('/[\\x80-\\xff]/', $string)) {
return $string;
}
}
// Run our transliterator for common symbols,
// This need to be executed before native php transliterator, because it may not have all required transliterators
$string = Transliterate::utf8_latin_to_ascii($string);
// Check if all symbols were transliterated (contains only ASCII),
// Otherwise try to use native php function if available
if (preg_match('/[\\x80-\\xff]/', $string) && function_exists('transliterator_transliterate') && function_exists('iconv')) {
return iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $string));
}
return StringHelper::strtolower($string);
}