Exemple #1
0
 /**
  * Compare original and translated strings to check abnormal length.
  * This is used in search views to warn of strings that look much wider
  * or much shorter than English
  *
  * @param  string $origin     The source string
  * @param  string $translated The string we want to compare to
  * @return string 'large' or 'small' or false if it doesn't look abnormal
  */
 public static function checkAbnormalStringLength($origin, $translated)
 {
     $origin_length = Strings::getLength($origin);
     $translated_length = Strings::getLength($translated);
     if ($origin_length != 0 && $translated_length != 0) {
         $difference = $translated_length / $origin_length * 100;
         $difference = round($difference);
         if ($origin_length > 100 && $difference > 150) {
             // Large translation for a large origin
             $abnormal_length = 'large';
         } elseif ($origin_length > 100 && $difference < 50) {
             // Small translation for a large origin
             $abnormal_length = 'small';
         } elseif ($origin_length < 100 && $difference > 200 && $translated_length > 100) {
             // Large translation for a small origin
             $abnormal_length = 'large';
         } elseif ($origin_length < 100 && $difference < 25) {
             // Small translation for a small origin
             $abnormal_length = 'small';
         } else {
             // No problems detected
             $abnormal_length = false;
         }
     } else {
         // Missing origin or translated string
         $abnormal_length = false;
     }
     return $abnormal_length;
 }
Exemple #2
0
 /**
  * @dataProvider getLengthDP
  */
 public function testGetLength($a, $b)
 {
     $obj = new _Strings();
     $this->integer($obj->getLength($a))->isEqualTo($b);
 }