コード例 #1
0
ファイル: Php.php プロジェクト: ppiedaderawnet/concrete5
 /**
  * Extracts translatable strings from PHP files with xgettext.
  *
  * @param string        $rootDirectory The base root directory
  * @param array[string] $phpFiles      The relative paths to the PHP files to be parsed
  *
  * @throws \Exception Throws an \Exception in case of problems
  *
  * @return \Gettext\Translations
  */
 protected static function parseDirectoryDo_php($rootDirectory, $phpFiles)
 {
     $prefix = $rootDirectory . '/';
     $originalExtractComments = \Gettext\Extractors\PhpCode::$extractComments;
     \Gettext\Extractors\PhpCode::$extractComments = 'i18n';
     $originalFunctions = \Gettext\Extractors\PhpCode::$functions;
     \Gettext\Extractors\PhpCode::$functions['t'] = '__';
     \Gettext\Extractors\PhpCode::$functions['t2'] = 'n__';
     \Gettext\Extractors\PhpCode::$functions['tc'] = 'p__';
     try {
         $absFiles = array_map(function ($phpFile) use($prefix) {
             return $prefix . $phpFile;
         }, $phpFiles);
         $newTranslations = \Gettext\Translations::fromPhpCodeFile($absFiles);
         \Gettext\Extractors\PhpCode::$extractComments = $originalExtractComments;
         \Gettext\Extractors\PhpCode::$functions = $originalFunctions;
     } catch (\Exception $x) {
         \Gettext\Extractors\PhpCode::$extractComments = $originalExtractComments;
         \Gettext\Extractors\PhpCode::$functions = $originalFunctions;
         throw $x;
     }
     $startAt = strlen($prefix);
     foreach ($newTranslations as $newTranslation) {
         $references = $newTranslation->getReferences();
         $newTranslation->deleteReferences();
         foreach ($references as $reference) {
             $newTranslation->addReference(substr($reference[0], $startAt), $reference[1]);
         }
     }
     return $newTranslations;
 }