Exemplo n.º 1
0
 /**
  * Find all of the ts() calls
  *
  * @param array $tokens the array with tokens from token_get_all()
  * @param string $file the string containing the file name
  * @param Pot $pot
  *
  * @return void
  */
 protected function findTsCalls($tokens, $file, Pot $pot)
 {
     // iterate through all the tokens while there's still a chance for
     // a ts() call
     while (count($tokens) > 3) {
         list($ctok, $par, $mid) = $tokens;
         // the first token has to be a T_STRING (with a function name)
         if (!is_array($ctok)) {
             array_shift($tokens);
             continue;
         }
         // check whether we're at ts(
         list($type, $string, $line) = $ctok;
         if ($type == T_STRING && ($string == 'ts' or $string == 't') && $par == '(') {
             switch ($this->tsCallType($tokens)) {
                 case TS_CALL_TYPE_SINGLE:
                     $pot->add(array('file' => $file, 'msgid' => $this->formatQuotedString($mid[1]), 'msgstr' => ''));
                     break;
                 case TS_CALL_TYPE_PLURAL:
                     $pot->add(array('file' => $file, 'msgid' => $this->formatQuotedString($mid[1]), 'msgid_plural' => $this->formatQuotedString($this->getPluralString($tokens)), 'msgstr[0]' => '', 'msgstr[1]' => ''));
                     break;
                 case TS_CALL_TYPE_INVALID:
                     $this->markerError($file, $line, 'ts', $tokens);
                     break;
                 default:
                     break;
             }
         }
         array_shift($tokens);
     }
 }
Exemplo n.º 2
0
 /**
  * Rips gettext strings from $file and prints them in C format.
  *
  * @param string $file
  * @param string $content
  * @param Pot $pot
  */
 public function parse($file, $content, Pot $pot)
 {
     if (empty($content)) {
         return;
     }
     // Match all calls to ts()
     // Note: \s also matches newlines with the 's' modifier.
     preg_match_all('~
   [^\\w]ts\\s*                                    # match "ts" with whitespace
   \\(\\s*                                         # match "(" argument list start
   ((?:(?:\'(?:\\\\\'|[^\'])*\'|"(?:\\\\"|[^"])*")(?:\\s*\\+\\s*)?)+)\\s*
   [,\\)]                                         # match ")" or "," to finish
   ~sx', $content, $matches);
     foreach ($matches[1] as $text) {
         if ($text = self::fs($text)) {
             $pot->add(array('file' => $file, 'msgid' => stripcslashes($text), 'msgstr' => ''));
         }
     }
 }