From de07ef83d4ceb206a30d7bf6dbab6323bc0b02b1 Mon Sep 17 00:00:00 2001 From: Filip Komar Date: Sun, 16 Mar 2014 13:55:38 +0000 Subject: fixed proper handling of fuzzy strings in reports --- langs/diff.php | 3 ++- langs/lib.php | 6 +++--- langs/report.php | 32 +++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/langs/diff.php b/langs/diff.php index bc6e0ab5a..686b90ea7 100644 --- a/langs/diff.php +++ b/langs/diff.php @@ -71,6 +71,7 @@ if ($gettext) { $issues = array( 'missing' => 'missing strings', + 'fuzzy_or_missing' => 'fuzzy or missing strings', 'notrans' => 'untranslated strings', 'extra' => 'unused (old) strings', 'dup_str' => 'duplicate strings', @@ -115,7 +116,7 @@ $s .= '

After translation:

'; foreach ($issues as $type => $name) { - if (count($diff[$type]) > 0) { + if (isset($diff[$type]) && $diff[$type] > 0) { $s .= sprintf('

%d %s:

', count($diff[$type]), $name); $s .= '
';
         if ($type == 'untranslated_lines_in_constitution') {
diff --git a/langs/lib.php b/langs/lib.php
index 15f133131..cfc40cf28 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -88,7 +88,7 @@ function _po_diff($locale, $resource)
 
     $pot_strings = array();
     $untrans = array();
-    $missing = array();
+    $fuzzy_or_missing = array();
 
     foreach ($source_l as $escaped_string => $subarray) {
         if (!empty($subarray["msgid"])) { // filter out header
@@ -108,14 +108,14 @@ function _po_diff($locale, $resource)
                 $untrans[] = $escaped_string;
             }
         } else {
-            $missing[] = $escaped_string;
+            $fuzzy_or_missing[] = $escaped_string;
         }
     }
 
     return array(
         'a'       => count($pot_strings), // # of original strings
 //        'b'       => count($po_strings), // # of target strings
-        'missing' => $missing,
+        'fuzzy_or_missing' => $fuzzy_or_missing,
         'notrans' => $untrans,
         'extra'   => array(),
         'dup_str' => array(),
diff --git a/langs/report.php b/langs/report.php
index 5725137d3..e0db9d987 100644
--- a/langs/report.php
+++ b/langs/report.php
@@ -51,6 +51,7 @@
         $enFiles    = array_merge(array('../_nav/langs/en.lang'), get_lang_references('*.lang'), get_lang_references('*.pot')); // added navigation file
         sort($enFiles);
     }
+    $num_of_enFiles = count($enFiles);
 
     if (isset($one_language) && $one_language != 'all') {
         $otherLangs = array('en', $one_language);
@@ -131,11 +132,16 @@
 
                 if ($gettext) {
                     $test = _po_diff($l, $resource);
+                    $num_of_missing_strings = 0;
+                    $num_of_fuzzy_or_missing_strings = count($test['fuzzy_or_missing']);
                 } else {
                     $test = _lang_diff($f, $langF);
+                    $num_of_missing_strings = count($test['missing']);
+                    $num_of_fuzzy_or_missing_strings = 0;
                 }
                 $num_of_untranslated_strings = count($test['notrans']);
                 $num_of_duplicated_strings   = count($test['dup_str']);
+                $num_of_extra_strings        = count($test['extra']);
 
                 if ($link == 'about/constitution') {
                     $constitution_results = aproximate_number_of_untranslated_constitution_lines(G_APP_ROOT, $l, $unique_lines_in_eng_constitution);
@@ -201,12 +207,13 @@
                 }
                 $link .= $page_not_linked . '';
 
-                if (count($test['missing']) === 0
+                if ($num_of_missing_strings === 0
+                    && $num_of_fuzzy_or_missing_strings === 0
                     && $num_of_untranslated_strings === 0) {
 
                     $extra = null;
-                    if (count($test['extra']) > 0) {
-                        $extra = ' ' . sprintf($diff_link, $f, $l) . '+' . count($test['extra']) . '';
+                    if ($num_of_extra_strings > 0) {
+                        $extra = ' ' . sprintf($diff_link, $f, $l) . '+' . $num_of_extra_strings . '';
                     }
                     if ($num_of_duplicated_strings > 0) {
                         $extra .= ' ' . sprintf($diff_link, $f, $l) . 'dup: ' . $num_of_duplicated_strings . '';
@@ -229,14 +236,17 @@
                         $cols .= sprintf('' . $diff_link,
                             $f, $l);
 
-                        if (count($test['missing']) > 0) {
-                            $cols .= count($test['missing']) . ' missing
'; + if ($num_of_missing_strings > 0) { + $cols .= $num_of_missing_strings . ' missing
'; + } + if ($num_of_fuzzy_or_missing_strings > 0) { + $cols .= $num_of_fuzzy_or_missing_strings . ' fuzzy or missing
'; } if ($num_of_untranslated_strings > 0) { $cols .= $num_of_untranslated_strings . ' untranslated
'; } - if (count($test['extra']) > 0) { - $cols .= count($test['extra']) . ' extra
'; + if ($num_of_extra_strings > 0) { + $cols .= $num_of_extra_strings . ' extra
'; } if ($num_of_duplicated_strings > 0) { $cols .= $num_of_duplicated_strings . ' duplicate'; @@ -244,7 +254,7 @@ } $cols .= ''; $cols .= $link . ''; - $done = $test['a'] - $num_of_untranslated_strings - count($test['missing']); + $done = $test['a'] - $num_of_untranslated_strings - $num_of_missing_strings - $num_of_fuzzy_or_missing_strings; } } $stats[$l]['strings'] += $done; @@ -256,7 +266,7 @@ } $num_clmns_to_repeat = 9; $num_of_col++; - if ($num_of_col % $num_clmns_to_repeat == 0 && $num_of_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) { + if ($num_of_col % $num_clmns_to_repeat == 0 && $num_of_col <= $num_of_enFiles - ($num_clmns_to_repeat / 3)) { if ($l == 'en') { $cols .= $lang_coloumn = 'Language'; } else { @@ -291,7 +301,7 @@ $lang_line = array(); $num_of_h_col = 0; $add_last_coloumn = FALSE; - $resources = ($restore_resources ? ' ' : count($enFiles) . ' resources'); + $resources = ($restore_resources ? ' ' : $num_of_enFiles . ' resources'); foreach ($enFiles as $lang_chunk) { $num_of_h_col++; if ($restore_resources) { @@ -299,7 +309,7 @@ } else { $lang_line[] = '' . str_replace('en/', '', $lang_chunk) . ''; } - if ($num_of_h_col % $num_clmns_to_repeat == 0 && $num_of_h_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) { + if ($num_of_h_col % $num_clmns_to_repeat == 0 && $num_of_h_col <= $num_of_enFiles - ($num_clmns_to_repeat / 3)) { $lang_line[] = $resources; $add_last_coloumn = TRUE; } -- cgit v1.2.1