Exemplo n.º 1
0
 /**
  * Test the parsing.
  *
  * @return void
  */
 public function testParseShortArray()
 {
     $file = new ContaoFile($this->getFixturesPath() . 'contao-parse3-short-array.php');
     $this->assertEquals(5, count($file->getKeys()));
     $this->assertEquals('a-a-1', $file->getValue('a.a.0'));
     $this->assertEquals('a-a-2', $file->getValue('a.a.1'));
     $this->assertEquals('a-b-1', $file->getValue('a.b.0'));
     $this->assertEquals('a-b-2', $file->getValue('a.b.1'));
     $this->assertEquals('a-b-c', $file->getValue('a.b.c'));
 }
 /**
  * Convert the source file to the destination file.
  *
  * @param XLiffFile  $src The source XLIFF file.
  *
  * @param ContaoFile $dst The destination Contao file.
  *
  * @return bool
  */
 protected function convert(XLiffFile $src, ContaoFile $dst)
 {
     $changed = false;
     foreach ($src->getKeys() as $key) {
         if (($value = $src->getTarget($key)) !== null) {
             if ($dst->getValue($key) != $value) {
                 $changed = true;
                 $dst->setValue($key, $value);
             }
         } else {
             if ($dst->getValue($key) !== null) {
                 $changed = true;
                 $dst->removeValue($key);
             }
         }
     }
     return $changed;
 }
 /**
  * Convert the source file to the destination file.
  *
  * @param OutputInterface $output An OutputInterface instance.
  *
  * @param ContaoFile      $src    The source Contao file.
  *
  * @param XLiffFile       $dst    The destination XLIFF file.
  *
  * @param ContaoFile      $base   The base Contao file.
  *
  * @return void
  */
 protected function convert(OutputInterface $output, ContaoFile $src, XLiffFile $dst, ContaoFile $base)
 {
     $baseKeys = $base->getKeys();
     foreach ($baseKeys as $key) {
         if (!($basVal = $base->getValue($key))) {
             $dst->remove($key);
             continue;
         }
         $dst->setSource($key, $basVal);
         if (($value = $src->getValue($key)) !== null) {
             $dst->setTarget($key, $value);
         }
     }
     foreach ($dst->getKeys() as $key) {
         if (!in_array($key, $baseKeys)) {
             $this->writelnVerbose($output, sprintf('Language key <info>%s</info> is not present in the source. Removing it.', $key));
             $dst->remove($key);
         }
     }
 }
 /**
  * Fetches the value from this entry.
  *
  * @return null|string
  */
 public function getValue()
 {
     return $this->doc->getValue($this->getKey());
 }