From ee2ca782d32a6a7dbbb759c801acc9be5db856cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= <mcihar@novell.com>
Date: Tue, 5 Apr 2011 15:28:02 +0200
Subject: [PATCH] Display warning about incomplete translations

---
 Documentation.html           |    3 +++
 libraries/.gitignore         |    1 +
 libraries/config.default.php |    7 +++++++
 main.php                     |   17 +++++++++++++++++
 scripts/remove-incomplete-mo |    9 +++++++++
 5 files changed, 37 insertions(+), 0 deletions(-)
 create mode 100644 libraries/.gitignore

diff --git a/Documentation.html b/Documentation.html
index af3c44b..baa3d1e 100644
--- a/Documentation.html
+++ b/Documentation.html
@@ -624,6 +624,9 @@ since this link provides funding for phpMyAdmin.
     You can set this parameter to <tt>TRUE</tt> to stop this message 
     from appearing.</dd>
 
+    <dd id="cfg_TranslationWarningThreshold">$cfg['TranslationWarningThreshold'] integer</dt>
+    <dd>Show warning about incomplete translations on certain threshold.</dd>
+
     <dt id="cfg_AllowThirdPartyFraming">$cfg['AllowThirdPartyFraming'] boolean</dt>
     <dd>Setting this to <tt>true</tt> allows a page located on a different
     domain to call phpMyAdmin inside a frame, and is a potential security
diff --git a/libraries/.gitignore b/libraries/.gitignore
new file mode 100644
index 0000000..ea4a1fd
--- /dev/null
+++ b/libraries/.gitignore
@@ -0,0 +1 @@
+language_stats.inc.php
diff --git a/libraries/config.default.php b/libraries/config.default.php
index d47b705..4ca31e7 100644
--- a/libraries/config.default.php
+++ b/libraries/config.default.php
@@ -62,6 +62,13 @@ $cfg['SuhosinDisableWarning'] = false;
 $cfg['McryptDisableWarning'] = false;
 
 /**
+ * Show warning about incomplete translations on certain threshold.
+ *
+ * @global boolean $cfg['TranslationWarningThreshold']
+ */
+$cfg['TranslationWarningThreshold'] = 80;
+
+/**
  * Allows phpMyAdmin to be included from a document located on
  * another domain; setting this to true is a potential security hole
  *
diff --git a/main.php b/main.php
index 431f65b..7a91242 100644
--- a/main.php
+++ b/main.php
@@ -355,6 +355,23 @@ if ($cfg['SuhosinDisableWarning'] == false && @ini_get('suhosin.request.max_valu
     }
 
 /**
+ * Warning about incomplete translations.
+ *
+ * The data file is created while creating release by ./scripts/remove-incomplete-mo
+ */
+if (file_exists('./libraries/language_stats.inc.php')) {
+    include('./libraries/language_stats.inc.php');
+    /*
+     * This message is intentionally not translated, because we're
+     * handling incomplete translations here and focus on english
+     * speaking users.
+     */
+    if (isset($GLOBALS['language_stats'][$lang]) && $GLOBALS['language_stats'][$lang] < $cfg['TranslationWarningThreshold']) {
+        trigger_error('You are using translation which is not complete, you are welcome to <a href="http://www.phpmyadmin.net/home_page/improve.php#translate">contribute to it</a>.', E_USER_NOTICE);
+    }
+}
+
+/**
  * prints list item for main page
  *
  * @param   string  $name   displayed text
diff --git a/scripts/remove-incomplete-mo b/scripts/remove-incomplete-mo
index ac82b60..863721c 100755
--- a/scripts/remove-incomplete-mo
+++ b/scripts/remove-incomplete-mo
@@ -10,6 +10,12 @@ set -e
 #
 THRESHOLD=50
 
+echo '<?php' > libraries/language_stats.inc.php
+echo '/* Automatically generated file, do not edit! */' >> libraries/language_stats.inc.php
+echo '/* Generated bt scripts/remove-incomplete-mo */' >> libraries/language_stats.inc.php
+echo '' >> libraries/language_stats.inc.php
+echo '$GLOBALS["language_stats"] = array (' >> libraries/language_stats.inc.php
+
 check() {
     lang=`echo $1 | sed 's@po/\(.*\)\.po@\1@'`
     STATS=`LANG=C  msgfmt --statistics -o /dev/null $1 2>&1`
@@ -29,6 +35,7 @@ check() {
         UNTRANSLATED=0
     fi
     PERCENT=`expr 100 \* $TRANSLATED / \( $TRANSLATED + $FUZZY + $UNTRANSLATED \) || true`
+    echo "    '$lang' => $PERCENT," >> libraries/language_stats.inc.php
 
     if [ $PERCENT -lt $THRESHOLD ] ; then
         echo "Removing $lang, only $PERCENT%"
@@ -45,3 +52,5 @@ for x in po/*.po  ; do
     check $x
 done
 
+echo ');' >> libraries/language_stats.inc.php
+echo '?>' >> libraries/language_stats.inc.php
-- 
1.7.4.1

