public function testGetLocaleString() { $message = new Message('foo'); $message->setDesc('bar'); $message->setNew(true); $existingMessage = new Message('foo'); $existingMessage->setDesc('bar'); $existingMessage->setNew(false); $this->assertEquals($message->getDesc(), $message->getLocaleString()); $this->assertEquals('', $existingMessage->getLocaleString()); }
/** * Merges a message from an existing translation catalogue. * * Do not use this if you want to merge a message from an extracted catalogue. * In these cases, use merge() instead. * * @param Message $message */ public function mergeExisting(Message $message) { if ($this->id !== $message->getId()) { throw new RuntimeException(sprintf('You can only merge messages with the same id. Expected id "%s", but got "%s".', $this->id, $message->getId())); } if (null !== ($meaning = $message->getMeaning())) { $this->meaning = $meaning; } if (null !== ($desc = $message->getDesc())) { $this->desc = $desc; } $this->new = $message->isNew(); if ($localeString = $message->getLocaleString()) { $this->localeString = $localeString; } }
/** * {@inheritDoc} */ public function mergeScanned(Message $message) { if ($this->getId() !== $message->getId()) { throw new RuntimeException(sprintf('You can only merge messages with the same id. Expected id "%s", but got "%s".', $this->id, $message->getId())); } $this->setSources($message->getSources()); $oldDesc = $this->getDesc(); if ($this->isWritable()) { if (null === $this->getMeaning()) { $this->setMeaning($message->getMeaning()); } if (null === $this->getDesc()) { $this->setDesc($message->getDesc()); } if (!$this->getLocaleString()) { $this->setLocaleString($message->getLocaleString()); } } $this->mergeXliffMeta($message, $oldDesc); }
/** * Merge a scanned message into an extising message. * * This method does essentially the same as {@link mergeExisting()} but with reversed operands. * Whereas {@link mergeExisting()} is used to merge an existing message into a scanned message (this), * {@link mergeScanned()} is used to merge a scanned message into an existing message (this). * The result of both methods is the same, except that the result will end up in the existing message, * instead of the scanned message, so extra information read from the existing message is not discarded. * * @param Message $message * * @author Dieter Peeters <*****@*****.**> */ public function mergeScanned(Message $message) { if ($this->id !== $message->getId()) { throw new RuntimeException(sprintf('You can only merge messages with the same id. Expected id "%s", but got "%s".', $this->id, $message->getId())); } if (null === $this->getMeaning()) { $this->meaning = $message->getMeaning(); } if (null === $this->getDesc()) { $this->desc = $message->getDesc(); } $this->sources = array(); foreach ($message->getSources() as $source) { $this->addSource($source); } if (!$this->getLocaleString()) { $this->localeString = $message->getLocaleString(); } }
/** * @param $message * @return Message\XliffMessage */ private function makeXliffMessage(Message $message) { $newMessage = new Message\XliffMessage($message->getId(), $message->getDomain()); $newMessage->setNew($message->isNew()); $newMessage->setLocaleString($message->getLocaleString()); $newMessage->setSources($message->getSources()); $newMessage->addNote('key: ' . $message->getId()); if ($desc = $message->getDesc()) { $newMessage->setDesc($desc); } return $newMessage; }
/** * @param Message $oldMessage * @param Message $newMessage */ private function checkConsistency(Message $oldMessage, Message $newMessage) { $oldDesc = $oldMessage->getDesc(); $newDesc = $newMessage->getDesc(); if (0 < strlen($oldDesc) && 0 < strlen($newDesc) && $oldDesc != $newDesc) { throw new \RuntimeException(sprintf("The message '%s' exists with two different descs: '%s' in %s, and '%s' in %s", $oldMessage->getId(), $oldMessage->getDesc(), current($oldMessage->getSources()), $newMessage->getDesc(), current($newMessage->getSources()))); } }
public function testMergeExisting() { $message = new Message('foo'); $message->setDesc('bar'); $existingMessage = new Message('foo'); $existingMessage->setLocaleString('foobar'); $existingMessage->setNew(false); $existingMessage->addSource(new FileSource('foo/bar')); $message->mergeExisting($existingMessage); $this->assertEquals('bar', $message->getDesc()); $this->assertEquals('foobar', $message->getLocaleString()); $this->assertFalse($message->isNew()); $this->assertEquals(array(), $message->getSources()); }