本文整理汇总了PHP中JMS\TranslationBundle\Model\Message::setDesc方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::setDesc方法的具体用法?PHP Message::setDesc怎么用?PHP Message::setDesc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\TranslationBundle\Model\Message
的用法示例。
在下文中一共展示了Message::setDesc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
public function extract()
{
$catalogue = new MessageCatalogue();
$collection = $this->router instanceof I18nRouter ? $this->router->getOriginalRouteCollection() : $this->router->getRouteCollection();
foreach ($collection->all() as $name => $route) {
if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
continue;
}
///////////////////////////////////////
// Begin customizations
$meaning = "Route Controller and method: " . $route->getDefault('_controller');
// set a default value
// prefix with zikula module url if requested
if ($route->hasDefault('_zkModule')) {
$zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix');
if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) {
$meaning = "This is a route from the " . $route->getDefault('_zkModule') . "Bundle and will include a translated prefix.";
}
}
// End customizations
///////////////////////////////////////
$message = new Message($name, $this->domain);
$message->setDesc($route->getPath());
if (isset($meaning)) {
$message->setMeaning($meaning);
}
$catalogue->add($message);
}
return $catalogue;
}
示例2: extract
public function extract()
{
$catalogue = new MessageCatalogue();
foreach ($this->i18nLoader->extract($this->router->getRouteCollection()) as $name => $route) {
$message = new Message($name, $this->domain);
$message->setDesc($route->getPattern());
$catalogue->add($message);
}
return $catalogue;
}
示例3: testExtractTemplate
public function testExtractTemplate()
{
$expected = new MessageCatalogue();
$path = __DIR__ . '/Fixture/template.html.php';
$message = new Message('foo.bar');
$message->addSource(new FileSource($path, 1));
$expected->add($message);
$message = new Message('baz', 'moo');
$message->setDesc('Foo Bar');
$message->addSource(new FileSource($path, 3));
$expected->add($message);
$this->assertEquals($expected, $this->extract('template.html.php'));
}
示例4: testExtract
public function testExtract()
{
$expected = new MessageCatalogue();
$message = new Message('security.authentication_error.foo', 'authentication');
$message->setDesc('%foo% is invalid.');
$message->addSource(new FileSource(__DIR__ . '/Fixture/MyAuthException.php', 31));
$expected->add($message);
$message = new Message('security.authentication_error.bar', 'authentication');
$message->setDesc('An authentication error occurred.');
$message->addSource(new FileSource(__DIR__ . '/Fixture/MyAuthException.php', 35));
$expected->add($message);
$this->assertEquals($expected, $this->extract('MyAuthException.php'));
}
示例5: testExtractTemplate
public function testExtractTemplate()
{
$expected = new MessageCatalogue();
$fileSourceFactory = $this->getFileSourceFactory();
$fixtureSplInfo = new \SplFileInfo(__DIR__ . '/Fixture/template.html.php');
$message = new Message('foo.bar');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 1));
$expected->add($message);
$message = new Message('baz', 'moo');
$message->setDesc('Foo Bar');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 3));
$expected->add($message);
$this->assertEquals($expected, $this->extract('template.html.php'));
}
示例6: extract
public function extract()
{
$catalogue = new MessageCatalogue();
$collection = $this->router instanceof I18nRouter ? $this->router->getOriginalRouteCollection() : $this->router->getRouteCollection();
foreach ($collection->all() as $name => $route) {
if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
continue;
}
$message = new Message($name, $this->domain);
$message->setDesc($route->getPath());
$catalogue->add($message);
}
return $catalogue;
}
示例7: testDumpStructureWithMetadata
public function testDumpStructureWithMetadata()
{
$catalogue = new MessageCatalogue();
$catalogue->setLocale('en');
$message = new Message('foo.bar.baz');
$message->setDesc('Foo');
$catalogue->add($message);
$message = new Message('foo.bar.moo');
$message->setMeaning('Bar');
$catalogue->add($message);
$message = new Message('foo.baz');
$catalogue->add($message);
$this->assertEquals($this->getOutput('structure_with_metadata'), $this->dump($catalogue, 'messages'));
}
示例8: testExtractWithSimpleTestFixtures
public function testExtractWithSimpleTestFixtures()
{
$expected = array();
$basePath = __DIR__ . '/Fixture/SimpleTest/';
$fileSourceFactory = new FileSourceFactory('faux');
// Controller
$message = new Message('controller.foo');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'Controller/DefaultController.php'), 27));
$message->setDesc('Foo');
$expected['controller.foo'] = $message;
// Form Model
$expected['form.foo'] = new Message('form.foo');
$expected['form.bar'] = new Message('form.bar');
// Templates
foreach (array('php', 'twig') as $engine) {
$message = new Message($engine . '.foo');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'Resources/views/' . $engine . '_template.html.' . $engine), 1));
$expected[$engine . '.foo'] = $message;
$message = new Message($engine . '.bar');
$message->setDesc('Bar');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'Resources/views/' . $engine . '_template.html.' . $engine), 3));
$expected[$engine . '.bar'] = $message;
$message = new Message($engine . '.baz');
$message->setMeaning('Baz');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'Resources/views/' . $engine . '_template.html.' . $engine), 5));
$expected[$engine . '.baz'] = $message;
$message = new Message($engine . '.foo_bar');
$message->setDesc('Foo');
$message->setMeaning('Bar');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'Resources/views/' . $engine . '_template.html.' . $engine), 7));
$expected[$engine . '.foo_bar'] = $message;
}
// File with global namespace.
$message = new Message('globalnamespace.foo');
$message->addSource($fileSourceFactory->create(new \SplFileInfo($basePath . 'GlobalNamespace.php'), 27));
$message->setDesc('Bar');
$expected['globalnamespace.foo'] = $message;
$actual = $this->extract(__DIR__ . '/Fixture/SimpleTest')->getDomain('messages')->all();
asort($expected);
asort($actual);
$this->assertEquals($expected, $actual);
}
示例9: testExtract
public function testExtract()
{
$expected = new MessageCatalogue();
$path = __DIR__ . '/Fixture/MyFormType.php';
$message = new Message('bar');
$message->addSource(new FileSource($path, 36));
$expected->add($message);
$message = new Message('form.states.empty_value');
$message->setDesc('Please select a state');
$message->addSource(new FileSource($path, 37));
$expected->add($message);
$message = new Message('form.label.lastname');
$message->setDesc('Lastname');
$message->addSource(new FileSource($path, 33));
$expected->add($message);
$message = new Message('form.label.firstname');
$message->addSource(new FileSource($path, 30));
$expected->add($message);
$this->assertEquals($expected, $this->extract('MyFormType.php'));
}
示例10: testExtractEdit
public function testExtractEdit()
{
$expected = new MessageCatalogue();
$path = __DIR__ . '/Fixture/edit.html.twig';
$message = new Message('header.edit_profile');
$message->addSource(new FileSource($path, 10));
$expected->add($message);
$message = new Message("text.archive");
$message->setDesc('Archive');
$message->setMeaning('The verb');
$message->addSource(new FileSource($path, 13));
$expected->add($message);
$message = new Message('button.edit_profile');
$message->addSource(new FileSource($path, 16));
$expected->add($message);
$message = new Message('link.cancel_profile');
$message->setDesc('Back to Profile');
$message->addSource(new FileSource($path, 17));
$expected->add($message);
$this->assertEquals($expected, $this->extract('edit.html.twig'));
}
示例11: addToCatalogue
/**
* @param string $id
* @param string $source
* @param null|string $domain
* @param null|string $desc
* @param null|string $meaning
*/
private function addToCatalogue($id, $source, $domain = null, $desc = null, $meaning = null)
{
if (null === $domain) {
$message = new Message($id);
} else {
$message = new Message($id, $domain);
}
$message->addSource($source);
if ($desc) {
$message->setDesc($desc);
}
if ($meaning) {
$message->setMeaning($meaning);
}
$this->catalogue->add($message);
}
示例12: testGetLocaleString
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());
}
示例13: enterNode
public function enterNode(\PHPParser_Node $node)
{
if (!$node instanceof \PHPParser_Node_Expr_MethodCall || !is_string($node->name) || 'trans' !== strtolower($node->name) && 'transchoice' !== strtolower($node->name)) {
$this->previousNode = $node;
return;
}
$ignore = false;
$desc = $meaning = null;
if (null !== ($docComment = $this->getDocCommentForNode($node))) {
foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
if ($annot instanceof Ignore) {
$ignore = true;
} else {
if ($annot instanceof Desc) {
$desc = $annot->text;
} else {
if ($annot instanceof Meaning) {
$meaning = $annot->text;
}
}
}
}
}
if ($ignore) {
return;
}
if (!$node->args[0]->value instanceof \PHPParser_Node_Scalar_String) {
$message = sprintf('Can only extract the translation id from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
if ($this->logger) {
$this->logger->err($message);
return;
}
throw new RuntimeException($message);
}
$id = $node->args[0]->value->value;
$index = 'trans' === strtolower($node->name) ? 2 : 3;
if (isset($node->args[$index])) {
if (!$node->args[$index]->value instanceof \PHPParser_Node_Scalar_String) {
$message = sprintf('Can only extract the translation domain from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
if ($this->logger) {
$this->logger->err($message);
return;
}
throw new RuntimeException($message);
}
$domain = $node->args[$index]->value->value;
} else {
$domain = 'messages';
}
$message = new Message($id, $domain);
$message->setDesc($desc);
$message->setMeaning($meaning);
$message->addSource(new FileSource((string) $this->file, $node->getLine()));
$this->catalogue->add($message);
}
示例14: testSetChecksConsistencyButAllowsEmptyDescs
public function testSetChecksConsistencyButAllowsEmptyDescs()
{
$col = new MessageCollection();
// both message have not desc
$msg = new Message('a');
$msg2 = new Message('a');
$col->set($msg);
$col->set($msg2);
// first message have a desc
$msg = new Message('b');
$msg->setDesc('b');
$msg2 = new Message('b');
$col->set($msg);
$col->set($msg2);
// second message have a desc
$msg = new Message('c');
$msg2 = new Message('c');
$msg2->setDesc('c');
$col->set($msg);
$col->set($msg2);
// non-null empty descs
$msg = new Message('d');
$msg->setDesc('d');
$msg2 = new Message('d');
$msg2->setDesc('');
$col->set($msg);
$col->set($msg2);
}
示例15: testMergeScanned
public function testMergeScanned()
{
$existingMessage = new XliffMessage('foo');
$existingMessage->setLocaleString('bar');
$existingMessage->addSource(new FileSource('bar'));
$existingMessage->setApproved(false);
$existingMessage->setState(XliffMessage::STATE_NONE);
$scannedMessage = new XliffMessage('foo');
$scannedMessage->setDesc('foo');
$scannedMessage->setApproved(true);
$scannedMessage->setState(XliffMessage::STATE_TRANSLATED);
$scannedMessage1 = new Message('foo');
$scannedMessage1->setDesc('foo');
$existingMessage1 = clone $existingMessage;
$scannedMessage1 = clone $scannedMessage;
$existingMessage1->mergeScanned($scannedMessage1);
$this->assertEquals('foo', $existingMessage1->getDesc());
$this->assertEquals('bar', $existingMessage1->getLocaleString());
$this->assertFalse($existingMessage1->isNew());
$this->assertEquals(array(), $existingMessage1->getSources());
$this->assertTrue($existingMessage1->isApproved());
$this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage1->getState());
$existingMessage2 = clone $existingMessage;
$existingMessage2->setDesc('bar');
$existingMessage2->setApproved(true);
$existingMessage2->setState(XliffMessage::STATE_TRANSLATED);
$scannedMessage2 = clone $scannedMessage;
$scannedMessage2->setDesc('foo');
$scannedMessage2->setApproved(false);
$scannedMessage2->setState(XliffMessage::STATE_NONE);
$existingMessage2->mergeScanned($scannedMessage2);
$this->assertEquals('bar', $existingMessage2->getDesc());
$this->assertFalse($existingMessage2->isNew());
$this->assertEquals(array(), $existingMessage2->getSources());
$this->assertTrue($existingMessage2->isApproved());
$this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage2->getState());
$existingMessage3 = clone $existingMessage;
$scannedMessage3 = clone $scannedMessage1;
$existingMessage3->mergeScanned($scannedMessage3);
$this->assertEquals('foo', $existingMessage3->getDesc());
$this->assertEquals('bar', $existingMessage3->getLocaleString());
$this->assertFalse($existingMessage3->isNew());
$this->assertEquals(array(), $existingMessage3->getSources());
$this->assertTrue($existingMessage3->isApproved());
$this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage3->getState());
$existingMessage4 = clone $existingMessage;
$existingMessage4->setDesc('bar');
$existingMessage4->setApproved(true);
$existingMessage4->setState(XliffMessage::STATE_TRANSLATED);
$scannedMessage4 = clone $scannedMessage1;
$scannedMessage4->setDesc('foo');
$existingMessage4->mergeScanned($scannedMessage4);
$this->assertEquals('bar', $existingMessage4->getDesc());
$this->assertEquals(array(), $existingMessage4->getSources());
$this->assertTrue($existingMessage4->isApproved());
$this->assertEquals(XliffMessage::STATE_TRANSLATED, $existingMessage4->getState());
}