mirror of
https://github.com/Karaka-Management/Build.git
synced 2026-01-11 11:48:40 +00:00
Create script for checking language files
This commit is contained in:
parent
fcaa51c7a4
commit
c929bb2d28
79
Tools/langUsageInspector.php
Normal file
79
Tools/langUsageInspector.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* Inspect .lang.php files and check them for errors/optimization
|
||||
*
|
||||
* @package Modules\HumanResourceManagement
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
function printUsage() : void
|
||||
{
|
||||
echo 'Usage: -d <DESTINATION_PATH> -m <MODULE_PATH>' . "\n\n";
|
||||
echo "\t" . '-d Destination/output directory.' . "\n";
|
||||
echo "\t" . '-m Module directory.' . "\n";
|
||||
}
|
||||
|
||||
$destination = ($key = \array_search('-d', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
|
||||
$modulePath = ($key = \array_search('-m', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
|
||||
|
||||
if (!isset($destination) || !isset($modulePath) ) {
|
||||
printUsage();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$sources = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modulePath));
|
||||
$tpls = [];
|
||||
$langs = [];
|
||||
|
||||
foreach ($sources as $source) {
|
||||
if ($source->isFile()
|
||||
&& (($temp = \strlen($source->getPathname()) - \strlen('tpl.php')) >= 0 && \strpos($source->getPathname(), 'tpl.php', $temp) !== false)
|
||||
) {
|
||||
$tpls[] = $source->getPathname();
|
||||
} elseif ($source->isFile()
|
||||
&& (($temp = \strlen($source->getPathname()) - \strlen('lang.php')) >= 0 && \strpos($source->getPathname(), 'lang.php', $temp) !== false)
|
||||
&& \strlen(\explode('.', \basename($source->getPathname()))[0]) === 2
|
||||
) {
|
||||
$langFileContent = include $source->getPathname();
|
||||
$langs[\explode('.', \basename($source->getPathname()))[0]] = \end($langFileContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Compare language files
|
||||
$length = 0;
|
||||
$unequalLength = false;
|
||||
$unusedLanguage = [];
|
||||
|
||||
foreach($langs as $lang => $data) {
|
||||
if ($length === 0) {
|
||||
$length = \count($data);
|
||||
$unusedLanguage = \array_keys($data);
|
||||
}
|
||||
|
||||
if ($length !== \count($data)) {
|
||||
$unequalLength = true;
|
||||
}
|
||||
|
||||
foreach ($tpls as $tpl) {
|
||||
$fileContent = \file_get_contents($tpl);
|
||||
|
||||
foreach ($data as $key => $word) {
|
||||
if (\stripos($fileContent, '$this->getHtml(\'' . $key . '\')') !== false
|
||||
&& ($key = \array_search($key, $unusedLanguage)) !== false
|
||||
) {
|
||||
unset($unusedLanguage[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo 'Language files have different length: ' . ($unequalLength ? 'yes' : 'no') . "\n";
|
||||
echo 'Unused language components: ' . "\n";
|
||||
var_dump($unusedLanguage);
|
||||
Loading…
Reference in New Issue
Block a user