Пример #1
0
 /**
  * Replace translation calls with translation result and return content
  *
  * @param string $content
  * @return string
  */
 public function translate($content)
 {
     foreach ($this->config->getPatterns() as $pattern) {
         $content = preg_replace_callback($pattern, [$this, 'replaceCallback'], $content);
     }
     return $content;
 }
Пример #2
0
 /**
  * Parse content for entries to be translated
  *
  * @param string $content
  * @return string[]
  * @throws \Exception
  */
 protected function getPhrases($content)
 {
     $phrases = [];
     foreach ($this->config->getPatterns() as $pattern) {
         $result = preg_match_all($pattern, $content, $matches);
         if ($result) {
             $phrases = array_merge($phrases, $matches[1]);
         }
         if (false === $result) {
             throw new \Exception(sprintf('Error while generating js translation dictionary: "%s"', error_get_last()));
         }
     }
     return $phrases;
 }
Пример #3
0
 public function testgetPatterns()
 {
     $this->assertEquals($this->patterns, $this->model->getPatterns());
 }