phpldapadmin/check_lang_files.php

87 lines
2.5 KiB
PHP
Raw Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/check_lang_files.php,v 1.11 2005/02/25 13:44:05 wurley Exp $
/**
* Test script to check that $lang variables in each language file.
* @package phpLDAPadmin
*/
/**
*/
2009-06-30 08:09:20 +00:00
2009-06-30 08:10:17 +00:00
echo "<html><head><title>phpldapadmin - check of translation</title></head><body>";
2009-06-30 09:24:29 +00:00
$CHECKLANG=$_REQUEST['CHECKLANG'];
2009-06-30 08:09:20 +00:00
2009-06-30 09:22:30 +00:00
include realpath( './lang/en.php' );
2009-06-30 08:09:20 +00:00
$english_lang = $lang;
unset( $lang );
2009-06-30 09:22:30 +00:00
$lang_dir = realpath( './lang/recoded' );
2009-06-30 08:09:20 +00:00
$dir = opendir( $lang_dir );
2009-06-30 09:22:30 +00:00
// First, detect any unused strings from the english language:
echo "<h1>Checking English language file for unused strings</h1>\n";
echo "<ol>\n";
$unused_keys = false;
// special case keys that do not occur hard-coded but are dynamically generated
$ignore_keys['equals'] = 1;
$ignore_keys['starts with'] = 1;
$ignore_keys['ends with'] = 1;
$ignore_keys['sounds like'] = 1;
$ignore_keys['contains'] = 1;
foreach( $english_lang as $key => $string ) {
if( isset( $ignore_keys[$key] ) )
continue;
$grep_cmd = "grep -r \"lang\[['\\\"]$key\" *.php templates/";
$used = `$grep_cmd`;
if( ! $used ) {
$unused_keys = true;
echo "<li>Unused English key: <tt>$key</tt> <br />&nbsp;&nbsp;&nbsp;&nbsp;(<small><tt>" . htmlspecialchars( $grep_cmd ) . "</tt></small>)</li>\n";
flush();
}
}
if( false === $unused_keys )
echo "No unused English strings.";
echo "</ol>\n";
echo "<h1>Incomplete or Erroneous Language Files</h1>\n\n";
2009-06-30 09:24:29 +00:00
if ($CHECKLANG)
printf("<h1>Checking language files %s</h1>\n\n",$CHECKLANG);
2009-06-30 09:22:30 +00:00
echo "<h1><A HREF='?'>check all languages</A></h1>\n";
flush();
2009-06-30 08:09:20 +00:00
while( ( $file = readdir( $dir ) ) !== false ) {
2009-06-30 09:22:30 +00:00
// skip the devel languages, english, and auto
if( $file == "zz.php" || $file == "zzz.php" || $file == "auto.php" || $file == "en.php" )
continue;
// Sanity check. Is this really a PHP file?
2009-06-30 08:09:20 +00:00
if( ! preg_match( "/\.php$/", $file ) )
continue;
unset( $lang );
$lang = array();
include realpath( $lang_dir.'/'.$file );
$has_errors = false;
2009-06-30 09:22:30 +00:00
if ($CHECKLANG=="" || $file===$CHECKLANG ){
2009-06-30 09:24:29 +00:00
echo "<h2><A HREF='?CHECKLANG=$file'>$file</A></h2>\n";
echo "<ol>\n";
2009-06-30 08:09:20 +00:00
foreach( $english_lang as $key => $string )
if( ! isset( $lang[ $key ] ) ) {
$has_errors = true;
2009-06-30 09:22:30 +00:00
echo "<li>missing entry: <tt>$key</tt></li>\n";
2009-06-30 08:09:20 +00:00
}
foreach( $lang as $key => $string )
if( ! isset( $english_lang[ $key ] ) ){
$has_errors = true;
2009-06-30 09:22:30 +00:00
echo "<li>extra entry: <tt>$key</tt></li>\n";
2009-06-30 08:09:20 +00:00
}
if( ! $has_errors )
2009-06-30 09:22:30 +00:00
echo "(No errors)\n";
}
echo "</ol>\n";
2009-06-30 08:09:20 +00:00
}
2009-06-30 08:10:17 +00:00
echo "</body></html>";
2009-06-30 08:09:20 +00:00
?>