00001 <?php
00002
00015
00016
00017
00018 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00019
00020 class localeCheck extends CommandLineTool {
00022 var $locales;
00023
00024 function localeCheck($args) {
00025 parent::CommandLineTool($args);
00026 array_shift($args);
00027 $this->locales = $args;
00028 }
00029
00033 function usage() {
00034 echo "Script to test locales for consistency\n"
00035 . "Usage: {$this->scriptName} [localeName (optional)] ...\n";
00036 }
00037
00041 function execute() {
00042 $plugins = PluginRegistry::loadAllPlugins();
00043
00044 foreach (Locale::getAllLocales() as $locale => $name) {
00045 if (!empty($this->locales) && !in_array($locale, $this->locales)) continue;
00046 if ($locale != MASTER_LOCALE) {
00047 echo "Testing locale \"$name\" ($locale) against reference locale " . MASTER_LOCALE . ".\n";
00048 $errors = Locale::testLocale($locale, MASTER_LOCALE);
00049 $this->displayLocaleErrors($locale, $errors);
00050
00051 $emailErrors = Locale::testEmails($locale, MASTER_LOCALE);
00052 $this->displayEmailErrors($locale, $emailErrors);
00053 }
00054 }
00055 }
00056
00057 function displayEmailErrors($locale, $errors) {
00058 ksort($errors);
00059 echo "\nERROR REPORT FOR EMAILS IN \"$locale\":\n";
00060 echo "-----------------------------------\n";
00061 foreach ($errors as $type => $errorList) {
00062 if (!empty($errorList)) switch ($type) {
00063 case EMAIL_ERROR_MISSING_EMAIL:
00064 echo "The following messages are missing from the emails file and need translation.\n";
00065 foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
00066 break;
00067 case EMAIL_ERROR_EXTRA_EMAIL:
00068 echo "\nThe following emails are not in the master translation and may be deleted:\n";
00069 foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
00070 break;
00071 case EMAIL_ERROR_DIFFERING_PARAMS:
00072 echo "\nThe following emails are missing parameters or have extra parameters and need\n";
00073 echo "correcting against the master translation:\n";
00074 foreach ($errorList as $error) {
00075 echo " - " . $error['key'] . "\n";
00076 echo " Mismatching parameter(s): " . implode(', ', $error['mismatch']) . "\n";
00077 }
00078 break;
00079 default: die("Unknown error type \"$type\"!\n");
00080 }
00081 }
00082 }
00083
00084 function displayLocaleErrors($locale, $errors) {
00085 ksort($errors);
00086 echo "\nERROR REPORT FOR LOCALE STRINGS IN \"$locale\":\n";
00087 echo "---------------------------------------\n";
00088 foreach ($errors as $type => $errorList) {
00089 if (!empty($errorList)) switch ($type) {
00090 case LOCALE_ERROR_MISSING_KEY:
00091 echo "The following keys are missing from a locale file and need to be translated.\n";
00092 foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
00093 break;
00094 case LOCALE_ERROR_EXTRA_KEY:
00095 echo "\nThe following keys are not in the master translation and may be deleted:\n";
00096 foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
00097 break;
00098 case LOCALE_ERROR_SUSPICIOUS_LENGTH:
00099 echo "\nThe following keys have suspicious lengths compared with the master translation\n";
00100 echo "and may need checking:\n";
00101 foreach ($errorList as $error) {
00102 $reference = $this->truncate($error['reference'], 65);
00103 $value = $this->truncate($error['value'], 65);
00104 echo " - " . $error['key'] . "\n";
00105 echo " \"" . $reference . "\" vs.\n";
00106 echo " \"" . $value . "\" ($locale)\n";
00107 }
00108 break;
00109 case LOCALE_ERROR_MISSING_FILE:
00110 echo "\nThe following locale files are missing:\n";
00111 foreach ($errorList as $error) {
00112 echo " - " . $error['filename'] . "\n";
00113 }
00114 break;
00115 case LOCALE_ERROR_DIFFERING_PARAMS:
00116 echo "\nThe following keys are missing parameters or have extra parameters and need\n";
00117 echo "correcting against the master translation:\n";
00118 foreach ($errorList as $error) {
00119 echo " - " . $error['key'] . "\n";
00120 echo " Mismatching parameter(s): " . implode(', ', $error['mismatch']) . "\n";
00121 }
00122 break;
00123 default: die("Unknown error type \"$type\"!\n");
00124 }
00125 }
00126 }
00127
00128 function truncate($value, $length = 80, $ellipsis = '...') {
00129 if (String::strlen($value) > $length) {
00130 $value = String::substr($value, 0, $length - String::strlen($ellipsis));
00131 return $value . $ellipsis;
00132 }
00133 return $value;
00134 }
00135
00136 }
00137
00138 $tool = &new localeCheck(isset($argv) ? $argv : array());
00139 $tool->execute();
00140
00141 ?>