/**
  * 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();
 }
Exemplo n.º 2
0
 protected function translate()
 {
     $translations_count = count($this->translations);
     $progress = new \cli\progress\Bar('Processing translations', $translations_count);
     foreach ($this->translations as $translation) {
         if (!$translation->getTranslation()) {
             $translatedText = $this->yandexTranslator->translate($translation->getOriginal(), $this->translateDirection);
             $translation->setTranslation($translatedText);
             $this->saveTranslations();
         }
         $progress->tick();
     }
 }
Exemplo n.º 3
0
}
Translator::$cacheDir = $tmp;
try {
    // translator
    $translator = new Translator($arguments['apikey']);
    $translator->httpOptions[CURLOPT_FAILONERROR] = false;
    $translator->httpOptions[CURLOPT_HTTP200ALIASES] = [400];
    // parser
    $po = new PoParser();
    $entries = $po->read($input);
    $previousEntries = null;
    if (file_exists($output)) {
        $previousEntries = $po->read($output);
    }
    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();
        }