public function testDifferentContextNotOverriden() { $testFilePath = 'testFile.po'; touch($testFilePath); $trlElements = array(array('type' => 'trlc', 'context' => 'salutation firstname male', 'text' => 'Dear {0}'), array('type' => 'trlc', 'context' => 'salutation firstname female', 'text' => 'Dear {0}')); $poFileGenerator = new PoFileGenerator($trlElements); $poFile = $poFileGenerator->generatePoFileObject($testFilePath); $this->assertTrue(strpos($poFile->compile(), 'salutation firstname male') !== false); $this->assertTrue(strpos($poFile->compile(), 'salutation firstname female') !== false); unlink($testFilePath); }
public function parse() { $kwfTrlElements = array(); if ($this->_kwfPoFilePath) { $this->_output->writeln('<info>Reading kwf-po file</info>'); $kwfPoFile = \Sepia\PoParser::parseFile($this->_kwfPoFilePath); $trlElementsExtractor = new TrlElementsExtractor($kwfPoFile); $kwfTrlElements = $trlElementsExtractor->extractTrlElements(); } $initDir = getcwd(); $this->_output->writeln('<info>Changing into directory</info>'); $repository = new Repository($this->_directory); $wc = $repository->getWorkingCopy(); if ($wc->getDiffPending()->getRawDiff() != '' || $wc->getDiffStaged()->getRawDiff() != '') { $this->_output->writeln('<error>Uncommited changes</error>'); exit; } chdir($initDir); $initBranch = trim($repository->run('rev-parse', array('--abbrev-ref', 'HEAD'))); $trlElements = array(); $errors = array(); $repository = new Repository($this->_directory); $repository->run('fetch', array('origin')); if ($this->_kwfPoFilePath) { $this->_output->writeln('<info>Iterating over branches matching "^[1-9]+.[0-9]+$"</info>'); } else { $this->_output->writeln('<info>Iterating over branches matching "^[3-9]+.[0-9]+$" and >=3.9</info>'); } foreach ($repository->getReferences()->getBranches() as $branch) { $branchName = $branch->getName(); if (strpos($branchName, 'origin/') === false) { continue; } $splited = explode('/', $branchName); $isVersionNumber = preg_match('/^[0-9]+.[0-9]+$/i', $splited[1]); if (sizeof($splited) >= 3) { continue; } if (!$isVersionNumber && $splited[1] != 'master' && $splited[1] != 'production') { continue; } if (!$this->_kwfPoFilePath && $isVersionNumber && version_compare($splited[1], '3.9', '<')) { continue; } $this->_output->writeln("<info>Checking out branch: {$branchName}</info>"); $wc->checkout($branchName); // parse package $this->_output->writeln('Parsing source directory...'); $parser = new ParseAll($this->_directory, $this->_output); $parser->setIgnoredFiles($this->_ignoredFiles); $trlElements = array_merge($parser->parseDirectoryForTrl(), $trlElements); $newErrors = $parser->getErrors(); foreach ($newErrors as $key => $error) { $newErrors[$key]['branch'] = $branchName; } $errors = array_merge($newErrors, $errors); } $wc->checkout($initBranch); $sources = array(); $filteredTrlElements = array(); foreach ($trlElements as $trlElement) { $sources[$trlElement['source']] = true; if ($trlElement['source'] == $this->_source) { $filteredTrlElements[] = $trlElement; } } $trlElements = $filteredTrlElements; // generate po file $this->_output->writeln('Generate Po-File...'); touch($this->_poFilePath); $this->_output->writeln($this->_poFilePath); $poFileGenerator = new PoFileGenerator($trlElements, $kwfTrlElements); $poFile = $poFileGenerator->generatePoFileObject($this->_poFilePath); $poFile->writeFile($this->_poFilePath); $this->_output->writeln(''); $this->_output->writeln('Trl Errors:'); foreach ($trlElements as $trlElement) { if (isset($trlElement['error_short']) && $trlElement['error_short']) { var_dump($trlElement); } } if (count($errors)) { $this->_output->writeln(''); $this->_output->writeln('Php Parse-Errors:'); foreach ($errors as $error) { $this->_output->writeln(' Branch: ' . $error['branch'] . ' | File: ' . $error['file']); $this->_output->writeln(' Error:' . $error['error']->getMessage()); $this->_output->writeln(' -------------------------------------'); } } $this->_output->writeln(''); $this->_output->writeln('Every branch has been parsed an data is collected in ' . $this->_poFilePath); $this->_output->writeln(''); $this->_output->writeln('1. Please check the mentioned Parse-Errors'); $this->_output->writeln('2. Upload and translate file from ' . $this->_poFilePath . ' to lingohub or translate in another way'); $this->_output->writeln('3. When using lingohub call "./vendor/bin/lingohub downloadTranslations" after translating'); $this->_output->writeln(''); }