From 4e92fedb5a6314351b255ae19d64227339b95274 Mon Sep 17 00:00:00 2001
From: Filip Komar
Date: Sat, 10 Aug 2013 14:55:24 +0000
Subject: report page extended to show duplicate strings in lang files
---
langs.inc.php | 11 ++++++++---
langs/diff.php | 2 +-
langs/lib.php | 10 ++++++----
langs/report.php | 10 +++++++++-
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/langs.inc.php b/langs.inc.php
index b06cfed04..da15b73d4 100644
--- a/langs.inc.php
+++ b/langs.inc.php
@@ -338,10 +338,11 @@ class i18n
* Get all locales from given file.
*
* @param string $file
+ * @param string $return_duplicates optional switch
*
* @return array
*/
- public static function _lang_return($file)
+ public static function _lang_return($file, $return_duplicates = false)
{
$strings = array();
@@ -356,9 +357,15 @@ class i18n
if ($C === ';' && !empty($f[$k+1])) {
$j = trim(substr($v, 1));
$j = str_replace(array("\'", "\""), array("'", '"'), $j);
+ if ($return_duplicates && !empty($strings[$j])) {
+ $duplicates[] = $j;
+ }
$strings[$j] = trim($f[$k+1]);
}
}
+ if (!empty($duplicates)) {
+ $strings['duplicates'] = $duplicates;
+ }
}
return $strings;
@@ -404,5 +411,3 @@ function _e($s = null, $args = null) { return i18n::_e($s, $args); }
function _h($s = null, $args = null, $tag = 'p') { return i18n::_h($s, $args, $tag); }
function _lang_load($locale, $domain) { return i18n::_lang_load($locale, $domain); }
-
-
diff --git a/langs/diff.php b/langs/diff.php
index d56be7f8e..68e741cd4 100644
--- a/langs/diff.php
+++ b/langs/diff.php
@@ -65,7 +65,7 @@ if($license) {
if($constitution || $license) {
$s .= 'Please read page on wiki for more information about that.
';
}
-foreach (array('missing' => 'missing strings', 'notrans' => 'untranslated strings', 'extra' => 'unused (old) strings') as $type => $name) {
+foreach (array('missing' => 'missing strings', 'notrans' => 'untranslated strings', 'extra' => 'unused (old) strings', 'dup_str' => 'duplicate strings') as $type => $name) {
if (count($diff[$type]) > 0) {
$s .= sprintf('%d %s:
', count($diff[$type]), $name);
diff --git a/langs/lib.php b/langs/lib.php
index db1fc21f5..091883292 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -21,13 +21,14 @@ include '../langs.inc.php';
function _lang_diff($a, $b)
{
$fa = i18n::_lang_return($a);
- $fb = i18n::_lang_return($b);
+ $fb = i18n::_lang_return($b, true); // option to return duplicates
+ $duplicates = (isset($fb['duplicates']) ? array_pop($fb) : null);
- $ret = array(
+/* $ret = array(
'aCount' => count($fa),
'bCount' => count($fb),
'diff' => count($fa) - count($fb),
- );
+ ); unused var */
$missing = array();
$notrans = array();
@@ -53,7 +54,8 @@ function _lang_diff($a, $b)
'b' => count($fb),
'missing' => $missing,
'notrans' => $notrans,
- 'extra' => $extra
+ 'extra' => $extra,
+ 'dup_str' => $duplicates,
);
}
diff --git a/langs/report.php b/langs/report.php
index 9a3e6967a..05d002836 100644
--- a/langs/report.php
+++ b/langs/report.php
@@ -105,6 +105,7 @@
$test = _lang_diff($f, $langF);
$num_of_untranslated_strings = count($test['notrans']);
+ $num_of_duplicated_strings = count($test['dup_str']);
if ($link == 'about/constitution') {
$dest_constitution = sprintf('%s/%s/%s/%s_%s.md', APP_ROOT, $l, 'about/constitution', 'mageia.org_statutes', $l);
@@ -167,6 +168,9 @@
if (count($test['extra']) > 0) {
$extra = ' ' . sprintf($diff_link, $f, $l) . '+' . count($test['extra']) . '';
}
+ if ($num_of_duplicated_strings > 0) {
+ $extra .= ' ' . sprintf($diff_link, $f, $l) . 'dup: ' . $num_of_duplicated_strings . '';
+ }
$cols .= sprintf('OK%s%s | ',
$langF, $extra, $link);
@@ -192,7 +196,11 @@
$cols .= $num_of_untranslated_strings . ' untranslated
';
}
if (count($test['extra']) > 0) {
- $cols .= count($test['extra']) . ' extra';
+ $cols .= count($test['extra']) . ' extra
';
+ }
+ if ($num_of_duplicated_strings > 0) {
+ $cols .= $num_of_duplicated_strings . ' duplicate';
+ $cols .= ($num_of_duplicated_strings > 1 ? 's' : '');
}
$cols .= '';
$cols .= $link . '';
--
cgit v1.2.1