From 3d0410bacd6ef860709aab5d6d319b1882939b00 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Sat, 17 Aug 2019 13:26:28 +0200 Subject: [PATCH] plugin_lang.php: Check additional_plugins, too. If you have the additional_plugins repo handy, you can just change the base path to check all that plugins, too. We shouldn't forget to check the UTF-8 directories. And we just have to catch all, even fatal, errors, due to missing function dependencies. Signed-off-by: Thomas Hochstein --- lang/plugin_lang.php | 78 +++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/lang/plugin_lang.php b/lang/plugin_lang.php index 71305769..51f9d708 100644 --- a/lang/plugin_lang.php +++ b/lang/plugin_lang.php @@ -25,6 +25,7 @@ if (!is_array($argv) || empty($argv[1])) { $lang = preg_replace('@[^a-z0-9]@', '', strtolower($argv[1])); echo "Probing language $lang\n"; $base = '../plugins/'; +#$base = '../../additional_plugins'; $d = @opendir($base); if (!$d) { @@ -33,42 +34,51 @@ if (!$d) { $const = array(); $const['checked'] = get_defined_constants(); -while(($file = readdir($d)) !== false) { - if ($file[0] == '.') { - continue; - } - - if (!is_dir($base . '/' . $file)) { - continue; - } - - $tfile = $base . '/' . $file . '/lang_en.inc.php'; - $sfile = $base . '/' . $file . '/lang_' . $lang . '.inc.php'; +try { + while(($file = readdir($d)) !== false) { + if ($file[0] == '.') { + continue; + } + + if (!is_dir($base . '/' . $file)) { + continue; + } + + $tfile = $base . '/' . $file . '/lang_en.inc.php'; + $sfile = $base . '/' . $file . '/lang_' . $lang . '.inc.php'; - if (file_exists($tfile)) { - echo "Parsing english language from $file - "; - include $tfile; - $current = get_defined_constants(); - $const['native'][$file] = array_diff($current, $const['checked']); - $const['checked'] = array_merge($const['checked'], $current); - echo count($const['native'][$file]) . " constants.\n"; - } else { - echo "NOTICE: English language of $file does not exist.\n\n"; - continue; + if (file_exists($tfile)) { + echo "Parsing english language from $file - "; + include $tfile; + $current = get_defined_constants(); + $const['native'][$file] = array_diff($current, $const['checked']); + $const['checked'] = array_merge($const['checked'], $current); + echo count($const['native'][$file]) . " constants.\n"; + } else { + echo "NOTICE: English language of $file does not exist.\n\n"; + continue; + } + + // Check for UTF-8 language files, too + if (!file_exists($sfile)) { + $sfile = $base . '/' . $file . '/UTF-8/lang_' . $lang . '.inc.php'; + } + if (file_exists($sfile)) { + echo "Parsing differences for $file - "; + include $sfile; + $current = get_defined_constants(); + $const['missing'][$file] = array_diff($current, $const['checked']); + $const['checked'] = array_merge($const['checked'], $current); + + echo count($const['missing'][$file]) . " missing constants.\n"; + } else { + $const['missing'][$file] = $const['native'][$file]; + } + echo "\n"; } - - if (file_exists($sfile)) { - echo "Parsing differences for $file - "; - include $sfile; - $current = get_defined_constants(); - $const['missing'][$file] = array_diff($current, $const['checked']); - $const['checked'] = array_merge($const['checked'], $current); - - echo count($const['missing'][$file]) . " missing constants.\n"; - } else { - $const['missing'][$file] = $const['native'][$file]; - } - echo "\n"; +} catch (Throwable $e) { + // Catch even fatal errors - we're just looking for constants + echo $e->getMessage(); } $const['missing'] = array_filter($const['missing']);