if (in_array('--force', $_SERVER['argv'])) { $update = true; } else { // Read existing POT file into $oldPot $oldPot = \Library\FileObject::fileGetContentsAsArray($potFileName, FILE_IGNORE_NEW_LINES); // Skip to first message string (strip header and first empty line) $startPos = array_search('', $oldPot, true); if ($startPos === false) { print "WARNING: File {$potFileName} as unexpected content. Skipping.\n"; continue; } $oldPot = array_slice($oldPot, $startPos + 1); $update = $newPot != $oldPot; } if ($update) { \Library\FileObject::FilePutContents($potFileName, sprintf($template, $module, implode("\n", $newPot))); print "Changes written to {$potFileName}.\n"; } else { print "No changes detected for {$potFileName}.\n"; } } // STAGE 2: Update .po files if necessary print "Updating .po files for {$module} module..."; foreach (new \GlobIterator("{$translationPath}/*.po", \GlobIterator::CURRENT_AS_PATHNAME) as $poFileName) { $cmd = array('msgmerge', '--quiet', '--update', '--backup=off', '--sort-by-file', escapeshellarg($poFileName), escapeshellarg($potFileName)); $cmd = implode(' ', $cmd); exec($cmd, $output, $result); if ($result) { print "ERROR: msgmerge returned with error code {$result}.\n"; print "Command line was:\n\n"; print "{$cmd}\n\n";