/** * Process image color data for all attachments. * * @subcommand process-all * @synopsis [--dry-run] [--count=<int>] [--offset=<int>] [--regenerate] */ public function process_all($args, $args_assoc) { $args_assoc = wp_parse_args($args_assoc, array('count' => 1, 'offset' => 0, 'dry-run' => false, 'regenerate' => false)); if (empty($page)) { $page = absint($args_assoc['offset']) / absint($args_assoc['count']); $page = ceil($page); if ($page < 1) { $page = 1; } } while (empty($no_more_posts)) { $query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'posts_per_page' => $args_assoc['count'], 'paged' => $page)); if (empty($progress_bar)) { $progress_bar = new cli\progress\Bar(sprintf('Processing images', absint($query->found_posts)), absint($query->found_posts), 100); $progress_bar->display(); } foreach ($query->posts as $post_id) { $progress_bar->tick(); $this->process(array($post_id), array('verbose' => false, 'dry-run' => $args_assoc['dry-run'], 'regenerate' => $args_assoc['regenerate'])); } if ($query->get('paged') >= $query->max_num_pages) { $no_more_posts = true; } if ($query->get('paged') === 0) { $page = 2; } else { $page = absint($query->get('paged')) + 1; } } $progress_bar->finish(); }
echo Colors::colorize('Translating : %b' . count($entries) . '%n entries from ' . $from . ' to ' . $to . PHP_EOL); $progress = new Bar('Translate status ', count($entries)); foreach ($entries as $entry => $data) { $translate = ""; $skipped = ""; if (isset($previousEntries) && !empty($previousEntries[$entry]['msgstr'][0])) { $skipped = "(skipped)"; $translate = $previousEntries[$entry]['msgstr'][0]; } else { $translate = $translator->translate($entry, $from, $to); } $po->update_entry($entry, $translate); if ($verbose) { echo $verbose ? " {$entry} => {$translate} {$skipped}" . PHP_EOL : null; } else { $progress->tick(); } } if (!$verbose) { $progress->finish(); } echo 'Save output to: ' . $output . PHP_EOL; $po->write($output); } catch (\DownloadException $e) { $response = @json_decode($e->getResponse()); if (isset($response->error->errors[0]->reason) && $response->error->errors[0]->reason === 'keyInvalid') { die(Colors::colorize('%rInvalid Google Translate API key%n' . PHP_EOL)); } else { die(Colors::colorize('%rError "' . $e->getMessage() . '"%n' . PHP_EOL)); } }