Ejemplo n.º 1
0
 /**
  * Get all source root directories
  */
 public function get_source_dirs($relative_to = '')
 {
     if (!$relative_to) {
         return $this->src;
     }
     // calculate path from location of given file (which may not exist)
     if (pathinfo($relative_to, PATHINFO_EXTENSION)) {
         $relative_to = dirname($relative_to);
     }
     $dirs = array();
     foreach ($this->src as $target_dir) {
         $dirs[] = loco_relative_path($relative_to, $target_dir);
     }
     return $dirs;
 }
Ejemplo n.º 2
0
 /**
  * Perform xgettext style extraction from PHP source files
  * @todo JavaScript files too
  * @todo filter on TextDomain?
  * @return array Loco's internal array format
  */
 public static function xgettext(LocoPackage $package, $relative_to = '')
 {
     class_exists('LocoPHPExtractor') or loco_require('build/gettext-compiled');
     $extractor = new LocoPHPExtractor();
     // parse out header tags in template files
     if ($package instanceof LocoThemePackage) {
         $extractor->set_wp_theme();
     } else {
         if ($package instanceof LocoPluginPackage) {
             $extractor->set_wp_plugin();
         }
     }
     $export = array();
     // extract from PHP sources, as long as source locations exist
     if ($srcdirs = $package->get_source_dirs()) {
         foreach ($srcdirs as $dir) {
             $fileref = loco_relative_path($relative_to, $dir);
             foreach (self::find_php($dir) as $path) {
                 $source = file_get_contents($path) and $tokens = token_get_all($source) and $export = $extractor->extract($tokens, str_replace($dir, $fileref, $path));
             }
         }
     } else {
         if ($path = $package->get_default_file()) {
             $dir = dirname($path);
             $fileref = loco_relative_path($relative_to, $dir);
             $source = file_get_contents($path) and $tokens = token_get_all($source) and $export = $extractor->extract($tokens, str_replace($dir, $fileref, $path));
         } else {
             if ($po = $package->get_po()) {
                 foreach ($po as $code => $path) {
                     $export = self::parse_po($path);
                     // strip translations, as this is intended as a POT
                     foreach ($export as $i => $message) {
                         $export[$i]['target'] = '';
                     }
                     break;
                 }
             }
         }
     }
     // add translatable header tags that won't have been in PHP
     if ($package instanceof LocoThemePackage) {
         $id = $target = '';
         foreach ($package->get_headers() as $tag => $source) {
             if ($source) {
                 $notes = str_replace('URI', ' URI', $tag) . ' of the theme';
                 $export[] = compact('id', 'source', 'target', 'notes');
             }
         }
     }
     return $export;
 }
Ejemplo n.º 3
0
 /**
  * Perform xgettext style extraction from PHP source files
  * @todo JavaScript files too
  * @todo filter on TextDomain?
  * @return array Loco's internal array format
  */
 public static function xgettext(LocoPackage $package, $relative_to = '')
 {
     class_exists('LocoPHPExtractor') or loco_require('build/gettext-compiled');
     $extractor = new LocoPHPExtractor();
     $export = array();
     // extract from PHP sources, as long as source locations exist
     if ($srcdirs = $package->get_source_dirs()) {
         foreach ($srcdirs as $dir) {
             $fileref = loco_relative_path($relative_to, $dir);
             foreach (self::find_php($dir) as $path) {
                 $source = file_get_contents($path) and $tokens = token_get_all($source) and $export = $extractor->extract($tokens, str_replace($dir, $fileref, $path));
             }
         }
     } else {
         if ($po = $package->get_po()) {
             foreach ($po as $code => $path) {
                 $export = self::parse_po($path);
                 // strip translations, as this is intended as a POT
                 foreach ($export as $i => $message) {
                     $export[$i]['target'] = '';
                 }
                 break;
             }
         }
     }
     return $export;
 }