Skip to content

Instantly share code, notes, and snippets.

@dannevang
Forked from Mark-H/compare.lexicon.php
Created June 19, 2014 12:58
Show Gist options
  • Save dannevang/ec63cd0d83e28df3e519 to your computer and use it in GitHub Desktop.
Save dannevang/ec63cd0d83e28df3e519 to your computer and use it in GitHub Desktop.
<?php
$default = realpath(dirname(__FILE__).'/core/lexicon/en').'/';
$local = realpath(dirname(__FILE__).'/core/lexicon/nl').'/';
$showSame = false;
// find default files
$theFiles = array();
if($handle = opendir($default)) {
while(false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..' && is_file($default.$file)) {
$theFiles[] = $file;
}
}
closedir($handle);
}
sort($theFiles);
// compare
$_lang = array();
foreach($theFiles as $filename) {
// load the local file
if (file_exists($local.$filename)) {
require_once($local.$filename);
$localLang = $_lang;
unset($_lang);
} else {
echo '<strong>'.$filename.'</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">File '.$filename.' does not exist in translated file</span><br /><br />';
continue;
}
// load the default
require_once($default.$filename);
$defaultLang = $_lang;
unset($_lang);
echo '<strong>'.$filename.'</strong><br />';
// compare keys
foreach ($defaultLang as $key => $value) {
if (!isset($localLang[$key])) {
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
echo 'The key <span style="color:red;">"'.$key.'"</span> <strong>doesn\'t exists</strong> in translated file<br />';
}
else if ($showSame && ($localLang[$key] == $value)) {
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<span style="color:gray;">The value of key "'.$key.'" is the <strong>same as the default</strong> ';
echo '(<strong>'.strip_tags(substr($localLang[$key], 0, 40)).'...</strong> vs. <strong>'.strip_tags(substr($value, 0, 40)).'...</strong>)</span><br />';
}
}
foreach ($localLang as $key => $value) {
if(!isset($defaultLang[$key])) {
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
echo 'The key "'.$key.'" exists in the translated file, but is <span style="color:blue;">removed by the default</span>.<br />';
}
}
echo '<br />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment