public function testStrings()
 {
     $file = new PoeditFile();
     $file->addString(new String('foo', 'bar', array('comment1')));
     $file->addString(new String('bar', 'baz', array('comment1')));
     $this->assertCount(2, $file->getStrings());
     $this->assertCount(1, $file->getString('foo')->getComments());
     $file->addString(new String('foo', 'bar', array('comment2')));
     $this->assertCount(2, $file->getStrings());
     $this->assertCount(2, $file->getString('foo')->getComments());
     $file->removeString('bar');
     $file->removeString('notfound');
     $this->assertCount(1, $file->getStrings());
     $this->assertTrue($file->hasString('foo'));
     $this->assertFalse($file->hasString('bar'));
 }
Exemple #2
0
 /**
  *   Dump PoeditFile into .po file
  *
  *   @param PoeditFile   $file
  *   @param string       $filename
  *   @param boolean      $sort       if enabled, sort strings and their comments. implemented to avoid too many git conflicts
  *   @param string       $charset
  *
  *   @return boolean
  */
 public function dump(PoeditFile $file, $filename = null, $sort = false, $charset = 'UTF-8')
 {
     $filename = null !== $filename ? $filename : $this->file;
     $content = $file->getHeaders() . PHP_EOL;
     $content .= "\"Content-Type: text/plain; charset=" . $charset . "\\n\"" . PHP_EOL . PHP_EOL;
     $strings = true === $sort ? $file->sortStrings()->getStrings() : $file->getStrings();
     foreach ($strings as $string) {
         $content .= true === $sort ? $string->sortReferences()->sortComments()->sortExtracteds()->sortFlags() : $string;
     }
     // ensure that path and file exists
     File::mkdirr(substr($filename, 0, strrpos($filename, '/')));
     return false !== file_put_contents($filename, $content);
 }