Beispiel #1
0
 /**
  * Construct package object from plugin array
  * note that handle is file path for plugins in WordPress
  */
 private static function get_plugin($handle)
 {
     $plugins = get_plugins();
     if (isset($plugins[$handle]) && is_array($plugins[$handle])) {
         $plugin = $plugins[$handle];
         $domain = $plugin['TextDomain'] or $domain = str_replace('/', '-', dirname($handle));
         if ('.' === $domain) {
             // single-file plugin has no directory to take a domain from
             $domain = substr(basename($handle), 0, -4);
         }
         $package = new LocoPluginPackage($handle, $domain, $plugin['Name'], $plugin['DomainPath']);
         // single-file plugins have no root, or anywhere to save POT file.
         if (false !== strpos($handle, '/')) {
             $root = WP_PLUGIN_DIR . '/' . dirname($handle);
             $package->add_source($root);
             // add PO and POT under plugin root
             if ($pofiles = LocoAdmin::find_po($root)) {
                 $package->add_po($pofiles, $domain);
             }
             // pick up any MO files that have missing PO
             if ($mofiles = LocoAdmin::find_mo($root)) {
                 $package->add_mo($mofiles, $domain);
             }
         }
         // find additional plugin PO under WP_LANG_DIR/plugin
         $package->add_lang_dir(WP_LANG_DIR . '/plugins', $domain);
         // fall back to all POT matches if no exact domain match
         if (!$package->pot && isset($pofiles)) {
             unset($pofiles['po']);
             $package->add_po($pofiles, null);
         }
         return $package;
     }
 }
Beispiel #2
0
 /**
  * Construct package object from plugin array
  * note that handle is file path for plugins in Wordpress
  */
 private static function get_plugin($handle)
 {
     $plugins = get_plugins();
     if (isset($plugins[$handle]) && is_array($plugins[$handle])) {
         $plugin = $plugins[$handle];
         $domain = $plugin['TextDomain'] or $domain = str_replace('/', '-', dirname($handle));
         $package = new LocoPluginPackage($handle, $domain, $plugin['Name'], $plugin['DomainPath']);
         $root = WP_PLUGIN_DIR . '/' . dirname($handle);
         $package->add_source($root);
         // add PO and POT under plugin root
         if ($pofiles = LocoAdmin::find_po($root)) {
             $package->add_po($pofiles, $domain);
         }
         // pick up any MO files that have missing PO
         if ($mofiles = LocoAdmin::find_mo($root)) {
             $package->add_mo($mofiles, $domain);
         }
         // find additional plugin PO under WP_LANG_DIR/plugin
         $package->add_lang_dir(WP_LANG_DIR . '/plugins', $domain);
         // fall back to all POT matches if no exact domain match
         if (!$package->pot) {
             unset($pofiles['po']);
             $package->add_po($pofiles, null);
         }
         return $package;
     }
 }