Jump to content


Tool to check a language file


  • You cannot reply to this topic
4 replies to this topic

#1 Daath

    Etomite Forum Newbie

  • Member
  • 23 posts

Posted 17 January 2005 - 05:36 AM

I wrote a small tool to help you find out what's missing from your language file:

<?php

    $f = $_GET['f'];
    if ( empty( $f ) || strpos( $f, '/' ) > 0 || !file_exists( "$f.inc.php" ) ) die( "Nope." );

    require( "english.inc.php" );
    $eng = array_keys( $_lang );
    unset( $_lang );
    require( "$f.inc.php" );
    $other = array_keys( $_lang );
    echo "Missing from $f.inc.php:<br><dl>";
    foreach ( $eng as $key )
    {
        if ( false === ( $dest = array_search( $key, $other ) ) )
        {
            echo "<dd>$key</dd>";
        }
        else 
        {
            unset( $other[ $dest ] );
        }
    }
    $other = array_unique( $other );
    echo "</dl>In $f.inc.php but not in english.inc.php:<br><dl>";
    foreach ( $other as $key )
    {
        if ( !in_array( $key, $eng ) )
        {
            echo "<dd>$key</dd>";            
        }
    }
    echo "</dl>";

?>

You place it in the folder where the language files are, and call it from the browser: http://example.com/manager/includes/lang/compare.php?f=dansk to check "dansk.inc.php"

#2 Guest_SniperX_*

  • Guests

Posted 17 January 2005 - 07:21 AM

That has to come under the heading of "How come nobody else though of that". Very handy.

For the record, things like this will be much easier in 0.7. as the language strings are contained in the database, not in language files.

#3 nikolajb

    Etomite Forum Newbie

  • Member
  • 47 posts

Posted 20 January 2005 - 11:05 AM

Yeah, thanks a lot for this little tool. It really helped us a lot with the danish translation.

#4 mrruben5

    Likes Etomite Forums!

  • Member
  • PipPip
  • 255 posts

Posted 23 August 2005 - 12:25 AM

Here's something I made to show where there were arraykeys missing. It's in atable and it has a nice style attached. Works best in gecko/opera
<?php

$f = $_GET['f'];
if ( empty( $f ) || strpos( $f, '/' ) > 0 || !file_exists( "$f.inc.php" ) ) {
	unset ($output);
	$output = "\t<p>Nope.</p>\n";
} else {

	require "english.inc.php";
	$english_translation = $_lang;
	unset ($_lang);
	
	require "$f.inc.php";
	
	
	# html on screen
	function htmlspecialchars_array($arr = array()) {
	   $rs =  array();
	   while(list($key,$val) = each($arr)) {
		   if(is_array($val)) {
			   $rs[$key] = htmlspecialchars_array($val);
		   }
		   else {
			   $rs[$key] = htmlspecialchars($val, ENT_QUOTES);
		   }   
	   }
	   return $rs;
	}
	
	$english_translation = htmlspecialchars_array($english_translation);
	$_lang = htmlspecialchars_array($_lang);
	
	# generate the output
	$output = "\t<table class=\"mainTable\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t<thead>\n\t\t\t<tr>\n\t\t\t\t<th>language key</th>\n\t\t\t\t<th>english.inc.php</th>\n\t\t\t\t<th>$f.inc.php</th>\n\t\t\t</tr>\n\t\t</thead>\n\t\t<tbody>\n";
	$num = 1;
	foreach ( $english_translation as $key => $value) {
		$_lang[$key] = isset($_lang[$key]) ? $_lang[$key] : "<span class=\"notSet\">\$_lang['$key'] not set!</span>";
		$output .= "\t\t\t<tr class=\"row$num\">\n\t\t\t\t<th width=\"1\">$key</th>\n\t\t\t\t<td>$value</td>\n\t\t\t\t<td>".$_lang[$key]."</td>\n\t\t\t</tr>\n";
		$num = $num == 2 ? 1 : 2;
	}
	$output .= "\t\t</tbody>\n\t\t<tfoot>\n\t\t\t<tr>\n\t\t\t\t<th>language key</th>\n\t\t\t\t<th>english</th>\n\t\t\t\t<th>$f</th>\n\t\t\t</tr>\n\t\t</tfoot>\n\t</table>\n";

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title>Values you need to add in <?=$f.".inc.php";?></title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />

<style type="text/css">
* { 
font-size: 11px;
margin: 0;
padding: 0;
border: 0;
}

body {
padding: 1em;
background: #fff;
font-family: verdana, tahoma, sans-serif;
}

table {
border:1px solid #eee;
padding:1px;
background:#fcfcfc;
width:100%;
}

table thead {
padding:0px;
margin:0px
}

table thead th {
margin:0px 1px;
background:#eee;
padding:.5em
}

table tr:hover {
background: #f6f6f6;
}

table th, table td {
padding:.3em;
}

table tbody td, table tbody th {
border-top:1px solid #eee;
}

table th {
text-align:right;
margin: 0 40% 0 0;
}

	
.notSet {
color: #C00;
font-weight: bold;
}

</style>

</head>

<body>

<?php echo $output; ?>

</body>
</html>


#5 Jeroen

    Likes Etomite Forums!

  • Member
  • PipPip
  • 178 posts

Posted 23 August 2005 - 01:11 PM

There is also a cool firefox plugin for translating language files.

See the extensions under development.
https://addons.mozilla.org/extensions/morei...numpg=10&id=687
or
http://phplangeditor.mozdev.org/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users