/**
  * Translaterates UTF-8 string to ASCII. (北京 to 'Bei Jing')
  *
  * Accepts language parameter that maps to a configurable array of special transliteration rules if present.
  *
  * @param string $text Text to transliterate
  * @param string $language Optional language for specific rules (falls back to current locale if not provided)
  * @return string
  */
 public function transliterate($text, $language = null)
 {
     $language = $language ?: $this->localizationService->getConfiguration()->getCurrentLocale()->getLanguage();
     if (isset($this->transliterationRules[$language])) {
         // Apply special transliteration (not supported in library)
         $text = strtr($text, $this->transliterationRules[$language]);
     }
     // Transliterate (transform 北京 to 'Bei Jing')
     if (preg_match('/[\\x80-\\xff]/', $text) && Transliterator::validUtf8($text)) {
         $text = Transliterator::utf8ToAscii($text);
     }
     return $text;
 }
 /**
  * @dataProvider provideUtf8ConversionCases
  */
 public function testUtf8Conversion($input, $expected)
 {
     $this->assertSame($expected, Transliterator::utf8ToAscii($input));
 }
Пример #3
0
 while (($line = fgets($handle)) !== false) {
     $found_any_delimiters = 0;
     foreach ($delimiters as $key) {
         $test = preg_match('/<' . $key[0] . ' ' . $key[1] . '/', $line);
         if ($test == 1) {
             //echo "found: ".$test.":".$line;
             $found_any_delimiters = 1;
             $part = \explode($key[0] . ' ' . $key[1] . '="', $line);
             //print_r($part);
             //echo "count: ".count($part);
             if (count($part) > 1) {
                 $altered .= $part[0] . $key[0] . ' ' . $key[1] . '="';
                 //echo "altered-1: ".$part[0] . $key[0].' '.$key[1].'="';
                 $subpart = \explode('"', $part[1], 2);
                 if (count($subpart) > 1) {
                     $trans = Transliterator::utf8ToAscii($subpart[0]);
                     $altered .= $trans . '"' . $subpart[1];
                     //echo "\naltered-2: ".$trans . '"'. $subpart[1];
                 } else {
                     $altered .= $part[1];
                     //echo "\naltered-2: ".$part[1];
                 }
                 //echo "\n";
             } else {
                 $altered .= $line;
             }
         }
     }
     if ($found_any_delimiters == 0) {
         $altered .= $line;
     }
Пример #4
0
 /**
  * Returns order description
  *
  * @return string
  */
 public function getDescription()
 {
     return Transliterator::utf8ToAscii($this->description);
 }