16 require(dirname(dirname(dirname(dirname(__FILE__)))) .
'/tools/bootstrap.inc.php');
24 public $dirs = [
'locale',
'lib/pkp/locale'];
32 if (!
sizeof($this->argv)) {
39 $this->localeKey = array_shift(
$argv);
41 if (
sizeof($this->argv) > 2) {
50 echo
"\nRemove a locale key from all locale files.\n\n"
51 .
" Usage: php {$this->scriptName} [localeKey] ([path] [path])\n\n"
52 .
" Remove locale keys from app:\n php {$this->scriptName} locale.key locale\n\n"
53 .
" Remove locale keys from pkp-lib:\n php {$this->scriptName} locale.key lib/pkp/locale\n\n"
54 .
" If no path is specified it will remove the locale\n key from files in both directories.\n\n";
62 $localeKeyLine =
'msgid "' . $this->localeKey .
'"';
63 $rootDir = dirname(dirname(dirname(dirname(__FILE__))));
65 foreach ($this->dirs as $dir) {
66 $locales = scandir($rootDir .
'/' . $dir);
67 foreach ($locales as $locale) {
68 if ($locale ===
'.' || $locale ===
'..') {
71 $localeDir = join(
'/', [$rootDir, $dir, $locale]);
72 $files = scandir($localeDir);
73 foreach ($files as $file) {
74 if ($file ===
'.' || $file ===
'..' || substr($file, -2) !==
'po') {
77 $content = file_get_contents($localeDir .
'/' . $file);
78 $lines = explode(
"\n", $content);
81 foreach($lines as $line) {
82 if ($localeKeyLine === substr($line, 0, strlen($localeKeyLine))) {
84 } elseif ($removing &&
'msgid' === substr($line, 0, strlen(
'msgid'))) {
92 file_put_contents($localeDir .
'/' . $file, join(
"\n", $newLines));
93 echo (
count($lines) -
count($newLines)) .
" lines removed from $localeDir/$file.\n";