if (!is_dir(dirname($output))) { die(Colors::colorize('%rDirectory "' . dirname($output) . '" not exists %n' . PHP_EOL)); } } if (!is_dir($tmp = __DIR__ . '/../tmp')) { mkdir($tmp, 0777); } 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); }