Skip to content

Commit

Permalink
adding checkAnormalStringLength function
Browse files Browse the repository at this point in the history
  • Loading branch information
tx2z committed Mar 6, 2013
1 parent af72e72 commit 18e0276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
7 changes: 5 additions & 2 deletions web/classes/Transvision/ShowResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
$source_string = Utils::highlightString($source_string);
$target_string = Utils::highlightString($target_string);

$lenght_diference = Utils::compareStringLength($source_string, $target_string);

// nbsp highlight
$target_string = str_replace(
' ',
Expand Down Expand Up @@ -126,13 +124,18 @@ public static function resultsTable($search_results, $recherche, $locale1, $loca
$path_locale1 = Utils::pathFileInRepo($locale1, $search_options['repo'], $key);
$path_locale2 = Utils::pathFileInRepo($locale2, $search_options['repo'], $key);

// check for final dot
if (substr(strip_tags($source_string), -1) == '.'
&& substr(strip_tags($target_string), -1) != '.') {
$missing_dot = '<em class="error">No final dot?</em>';
} else {
$missing_dot = '';
}


$lenght_diference = Utils::checkAnormalStringLength($source_string, $target_string);

// Missing string error
if (!$source_string) {
$source_string = '<em class="error">warning: missing string</em>';
$missing_dot = '';
Expand Down
30 changes: 24 additions & 6 deletions web/classes/Transvision/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,15 +537,33 @@ public static function cleanSearch($str)
*
* @param $origin en-US string
* @param $translated locale string
* @return $diference
* @return $anormalLength true or false
*/
public static function compareStringLength($origin, $translated)
public static function checkAnormalStringLength($origin, $translated)
{
$origin_length = strlen(strip_tags($origin));
$translated_length = strlen(strip_tags($translated));
$diference = ( $translated_length / $origin_length ) * 100;
$diference = round($diference);
$diference = $origin_length . ' - ' . $translated_length . ' - ' . $diference;
return $diference;

if ($origin_length != 0 && $translated_length != 0) {
$diference = ( $translated_length / $origin_length ) * 100;
$diference = round($diference);

if ($origin_length > 100 && $diference > 150) { //origen+100 traduccion muy larga
$anormalLength = 'A true' . $origin_length . ' - ' . $translated_length . ' - ' . $diference;
} elseif ($origin_length > 100 && $diference < 50) { //origen+100 traduccion muy corta
$anormalLength = 'B true' . $origin_length . ' - ' . $translated_length . ' - ' . $diference;
} elseif ($origin_length < 100 && $diference > 200) { //origen-100 traduccion muy larga
$anormalLength = 'C true' . $origin_length . ' - ' . $translated_length . ' - ' . $diference;
} elseif ($origin_length < 100 && $diference < 25) { //origen-100 traduccion muy corta
$anormalLength = 'D true' . $origin_length . ' - ' . $translated_length . ' - ' . $diference;
} else {
$anormalLength = 'false' . $origin_length . ' - ' . $translated_length . ' - ' . $diference;
}
} else {
$anormalLength = 'false - 0';
}


return $anormalLength;
}
}

0 comments on commit 18e0276

Please sign in to comment.