Created
June 19, 2014 12:50
-
-
Save Mark-H/79c92100aac1772f69f4 to your computer and use it in GitHub Desktop.
compare.lexicon.php - A super useful script for people that want to update translations for MODX (or MODX Extras) and need to get a good at a glance view of the changes. Got it from the forums somewhere in the past, but can't find the original source now. It probably changed a bit over the years too.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 /> <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 ' '; | |
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 ' '; | |
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 ' '; | |
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
There's also http://forums.modx.com/thread/?thread=51022&page=1 which looks useful