php - JMSTranslationBundle extract translation key in Entity static function -


i have static function in entity contains translation keys in array.

public static function astaticfunction() {     return array(         0 => 'a.translation.key',         'another.translation.key',     ); } 

when run extract command of jmstranslationbundle, translation keys not extracted. how make detect , extract them?

the jmstranslationbundle not extracting translation keys entity. so, here did:

create service , tag jms_translation.file_visitor:

acmecustom.translator.entity.extractor:     class: acme\custombundle\translator\entityextractor     tags:         - { name: jms_translation.file_visitor } 

and extractor class (some lines/functions truncated):

<?php namespace acme\custombundle\translator;  use jms\translationbundle\model\filesource; use jms\translationbundle\model\message; use jms\translationbundle\model\messagecatalogue; use jms\translationbundle\translation\extractor\filevisitorinterface;  class entityextractor implements filevisitorinterface, \phpparser_nodevisitor {     private $traverser;     private $catalogue;     private $file;      public function __construct()     {         $this->traverser = new \phpparser_nodetraverser();         $this->traverser->addvisitor($this);     }      public function enternode(\phpparser_node $node)     {         if (!$node instanceof \phpparser_node_scalar_string) {             return;         }          $id = $node->value;          // ignore multiple dot without string between them         if (preg_match('/(\.\.|\.\.\.)/', $id)) {             return;         }          // extract dot-delimitted string such "custom.entity.firstname"         if (preg_match('/.*\./', $id)) {             $domain = 'messages';             $message = new message($id, $domain);             $message->addsource(new filesource((string) $this->file, $node->getline()));              $this->catalogue->add($message);         }     }      public function visitphpfile(\splfileinfo $file, messagecatalogue $catalogue, array $ast)     {         $this->file = $file;         $this->catalogue = $catalogue;          // extract path/directory 'entity'         if ($this->file->getpathinfo()->getfilename() == 'entity') {             $this->traverser->traverse($ast);         }     } } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -