当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::addSource方法代码示例

本文整理汇总了PHP中JMS\TranslationBundle\Model\Message::addSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::addSource方法的具体用法?PHP Message::addSource怎么用?PHP Message::addSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JMS\TranslationBundle\Model\Message的用法示例。


在下文中一共展示了Message::addSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDumpStructure

 public function testDumpStructure()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale('en');
     $message = new Message('foo.bar.baz');
     $message->addSource(new FileSource('/a/b/c/foo/bar', 1, 2));
     $message->addSource(new FileSource('bar/baz', 1, 2));
     $catalogue->add($message);
     $this->assertEquals($this->getOutput('structure'), $this->dump($catalogue, 'messages'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:10,代码来源:BaseDumperTest.php

示例2: getTranslationMessages

 public static function getTranslationMessages()
 {
     $messages = array();
     foreach (self::$choices as $trans) {
         $message = new Message($trans);
         $message->addSource(new FileSource(__FILE__, 13));
         $messages[] = $message;
     }
     return $messages;
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:10,代码来源:MyFormModel.php

示例3: testExtractFormModel

 public function testExtractFormModel()
 {
     $expected = new MessageCatalogue();
     $path = __DIR__ . '/Fixture/MyFormModel.php';
     $message = new Message('form.label.choice.foo');
     $message->addSource(new FileSource($path, 13));
     $expected->add($message);
     $message = new Message('form.label.choice.bar');
     $message->addSource(new FileSource($path, 13));
     $expected->add($message);
     $this->assertEquals($expected, $this->extract('MyFormModel.php'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:12,代码来源:TranslationContainerExtractorTest.php

示例4: 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'));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:13,代码来源:DefaultPhpFileExtractorTest.php

示例5: testExtractValidationMessages

 public function testExtractValidationMessages()
 {
     $fileSourceFactory = $this->getFileSourceFactory();
     $fixtureSplInfo = new \SplFileInfo(__DIR__ . '/Fixture/MyEntity.php');
     $expected = new MessageCatalogue();
     $message = new Message('entity.default');
     $message->addSource($fileSourceFactory->create($fixtureSplInfo, 15));
     $expected->add($message);
     $message = new Message('entity.custom-domain', 'custom-domain');
     $message->addSource($fileSourceFactory->create($fixtureSplInfo, 22));
     $expected->add($message);
     $this->assertEquals($expected, $this->extract('MyEntity.php'));
 }
开发者ID:php-community,项目名称:JMSTranslationBundle,代码行数:13,代码来源:ValidationContextExtractorTest.php

示例6: 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'));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:13,代码来源:AuthenticationMessagesExtractorTest.php

示例7: 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'));
 }
开发者ID:kazak,项目名称:forum,代码行数:14,代码来源:DefaultPhpFileExtractorTest.php

示例8: enterNode

 public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
 {
     $this->stack[] = $node;
     if ($node instanceof \Twig_Node_Expression_Function) {
         $name = $node->getAttribute('name');
         if (in_array($name, $this->methodNames)) {
             $args = $node->getNode('arguments');
             switch ($name) {
                 case '_n':
                 case '_fn':
                     $id = $args->getNode(0)->getAttribute('value') . '|' . $args->getNode(1)->getAttribute('value');
                     break;
                 default:
                 case '__f':
                 case '__':
                     $id = $args->getNode(0)->getAttribute('value');
                     break;
             }
             // obtain translation domain from composer file
             $composerPath = str_replace($this->file->getRelativePathname(), '', $this->file->getPathname());
             if (isset(self::$domainCache[$composerPath])) {
                 $domain = self::$domainCache[$composerPath];
             } else {
                 $scanner = new Scanner();
                 $scanner->scan(array($composerPath), 1);
                 $metaData = $scanner->getModulesMetaData(true);
                 $domains = array_keys($metaData);
                 if (isset($domains[0])) {
                     $domain = strtolower($domains[0]);
                     // cache result of file lookup
                     self::$domainCache[$composerPath] = $domain;
                 } else {
                     $domain = 'messages';
                 }
             }
             $domainNode = array_search($name, $this->methodNames);
             $domain = $args->hasNode($domainNode) ? $args->getNode($domainNode)->getAttribute('value') : $domain;
             $message = new Message($id, $domain);
             $message->addSource(new FileSource((string) $this->file, $node->getLine()));
             $this->catalogue->add($message);
         }
     }
     return $node;
 }
开发者ID:rmaiwald,项目名称:core,代码行数:44,代码来源:ZikulaTwigFileExtractor.php

示例9: enterNode

 public function enterNode(\PHPParser_Node $node)
 {
     if (!$node instanceof \PHPParser_Node_Scalar_String) {
         return;
     }
     $id = $node->value;
     if (preg_match('/(\\.\\.|\\.\\.\\.)/', $id)) {
         return;
     }
     if (preg_match('/^http/', $id)) {
         return;
     }
     if (preg_match('/.*\\./', $id)) {
         $domain = 'messages';
         $message = new Message($id, $domain);
         $message->addSource(new FileSource((string) $this->file, $node->getLine()));
         $this->catalogue->add($message);
     }
 }
开发者ID:alisyihab,项目名称:sisdik,代码行数:19,代码来源:EntityExtractor.php

示例10: 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);
 }
开发者ID:kazak,项目名称:forum,代码行数:42,代码来源:FileExtractorTest.php

示例11: 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'));
 }
开发者ID:nikic,项目名称:JMSTranslationBundle,代码行数:20,代码来源:FormExtractorTest.php

示例12: visitPhpFile

 public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast)
 {
     $this->catalogue = $catalogue;
     // Traverse document to assemble class name
     $traverser = new \PHPParser_NodeTraverser();
     $traverser->addVisitor($this);
     $traverser->traverse($ast);
     if ($this->annotated) {
         // Get annotations for the class
         $annotationDriver = new Annotation(new DoctrineAnnotationReader());
         $manager = new Manager();
         $manager->addDriver($annotationDriver, -1);
         $metadata = $manager->getMetadata($this->parsedClassName);
         // Save messages for title
         foreach ($metadata->getFields() as $field) {
             $mappedField = $metadata->getFieldMapping($field);
             if ((!isset($mappedField['visible']) || $mappedField['visible']) && isset($mappedField['title'])) {
                 $message = new Message($mappedField['title']);
                 $message->addSource(new FileSource((string) $file));
                 $catalogue->add($message);
             }
         }
     }
 }
开发者ID:muchar,项目名称:APYDataGridBundle,代码行数:24,代码来源:ColumnTitleAnnotationTranslationExtractor.php

示例13: addMessage

 /**
  * @param string $id
  * @param string $domain
  */
 private function addMessage($id, $domain)
 {
     $message = new Message($id, $domain);
     //        $this->logger->debug(sprintf('extract: %s - domain:%s', $id, $domain));
     $trace = debug_backtrace(false);
     if (isset($trace[1]['file'])) {
         $message->addSource(new FileSource($trace[1]['file']));
     }
     $this->catalogue->add($message);
 }
开发者ID:robhunt3r,项目名称:SonataAdminBundle,代码行数:14,代码来源:AdminExtractor.php

示例14: testEmbeddedTemplate

 public function testEmbeddedTemplate()
 {
     $expected = new MessageCatalogue();
     $fileSourceFactory = $this->getFileSourceFactory();
     $fixtureSplInfo = new \SplFileInfo(__DIR__ . '/Fixture/embedded_template.html.twig');
     $message = new Message('foo');
     $message->addSource($fileSourceFactory->create($fixtureSplInfo, 3));
     $expected->add($message);
     $this->assertEquals($expected, $this->extract('embedded_template.html.twig'));
 }
开发者ID:kazak,项目名称:forum,代码行数:10,代码来源:TwigFileExtractorTest.php

示例15: getStructureCatalogue

 /**
  * Get the catalogue used for the structure tests
  *
  * @return MessageCatalogue
  */
 protected function getStructureCatalogue()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale('en');
     $message = new Message('foo.bar.baz');
     $message->addSource(new FileSource('/z/order/test', 1, 2));
     $message->addSource(new FileSource('bar/baz', 1, 2));
     $message->addSource(new FileSource('bar/baz', 1, 5));
     $message->addSource(new FileSource('/a/b/c/foo/bar', 1, 2));
     $catalogue->add($message);
     return $catalogue;
 }
开发者ID:kazak,项目名称:forum,代码行数:17,代码来源:XliffDumperTest.php


注:本文中的JMS\TranslationBundle\Model\Message::addSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。