Skip to content
Snippets Groups Projects
Commit ab45df19 authored by Demian Katz's avatar Demian Katz
Browse files

Added "language delete" utility.

parent a686d90d
No related merge requests found
...@@ -81,6 +81,7 @@ class Module implements \Zend\ModuleManager\Feature\ConsoleUsageProviderInterfac ...@@ -81,6 +81,7 @@ class Module implements \Zend\ModuleManager\Feature\ConsoleUsageProviderInterfac
'import import-xsl' => 'XSLT importer', 'import import-xsl' => 'XSLT importer',
'import webcrawl' => 'Web crawler', 'import webcrawl' => 'Web crawler',
'language copystring' => 'Copy one language string to another', 'language copystring' => 'Copy one language string to another',
'language delete' => 'Remove a language string from all files',
'language normalize' => 'Normalize a directory of language files', 'language normalize' => 'Normalize a directory of language files',
'util createHierarchyTrees' => 'Cache populator for hierarchies', 'util createHierarchyTrees' => 'Cache populator for hierarchies',
'util cssBuilder' => 'LESS compiler', 'util cssBuilder' => 'LESS compiler',
......
...@@ -90,6 +90,59 @@ class LanguageController extends AbstractBase ...@@ -90,6 +90,59 @@ class LanguageController extends AbstractBase
return $this->getSuccessResponse(); return $this->getSuccessResponse();
} }
/**
* Delete a language string to another
*
* @return \Zend\Console\Response
*/
public function deleteAction()
{
// Display help message if parameters missing:
$argv = $this->consoleOpts->getRemainingArgs();
if (!isset($argv[0])) {
Console::writeLine(
"Usage: {$_SERVER['argv'][0]} [source] [target]"
);
Console::writeLine("\ttarget - the target key to remove");
return $this->getFailureResponse();
}
$normalizer = new ExtendedIniNormalizer();
$target = $argv[0] . ' = "';
$langDir = realpath(__DIR__ . '/../../../../../languages');
$handle = opendir($langDir);
if (!$handle) {
Console::writeLine("Could not open directory $langDir");
return $this->getFailureResponse();
}
while ($file = readdir($handle)) {
// Only process .ini files, and ignore native.ini special case file:
if (substr($file, -4) == '.ini' && $file !== 'native.ini') {
Console::writeLine("Processing $file...");
$full = $langDir . '/' . $file;
$lines = file($full);
$out = '';
$found = false;
foreach ($lines as $line) {
if (substr($line, 0, strlen($target)) !== $target) {
$out .= $line;
} else {
$found = true;
}
}
if ($found) {
file_put_contents($full, $out);
$normalizer->normalizeFile($full);
} else {
Console::writeLine("Source key not found.");
}
}
}
return $this->getSuccessResponse();
}
/** /**
* Normalizer * Normalizer
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment