Пример #1
0
 function wp_theme($dir, $output, $slug = null)
 {
     $placeholders = array();
     // guess plugin slug
     if (is_null($slug)) {
         $slug = $this->guess_plugin_slug($dir);
     }
     $main_file = $dir . '/style.css';
     $source = $this->get_first_lines($main_file, $this->max_header_lines);
     $placeholders['version'] = $this->get_addon_header('Version', $source);
     $placeholders['author'] = $this->get_addon_header('Author', $source);
     $placeholders['name'] = $this->get_addon_header('Theme Name', $source);
     $placeholders['slug'] = $slug;
     $license = $this->get_addon_header('License', $source);
     if ($license) {
         $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}.";
     } else {
         $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package.";
     }
     $output = is_null($output) ? "{$slug}.pot" : $output;
     $res = $this->xgettext('wp-theme', $dir, $output, $placeholders);
     if (!$res) {
         return false;
     }
     $potextmeta = new PotExtMeta();
     $res = $potextmeta->append($main_file, $output, array('Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI'));
     if (!$res) {
         return false;
     }
     // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4.
     $extract_templates = !in_array($slug, array('twentyten', 'twentyeleven', 'default', 'classic'));
     if (!$extract_templates) {
         $wp_dir = dirname(dirname(dirname($dir)));
         $extract_templates = file_exists("{$wp_dir}/wp-admin/user/about.php") || !file_exists("{$wp_dir}/wp-load.php");
     }
     if ($extract_templates) {
         $res = $potextmeta->append($dir, $output, array('Template Name'));
         if (!$res) {
             return false;
         }
         $files = scandir($dir);
         foreach ($files as $file) {
             if ('.' == $file[0] || 'CVS' == $file) {
                 continue;
             }
             if (is_dir($dir . '/' . $file)) {
                 $res = $potextmeta->append($dir . '/' . $file, $output, array('Template Name'));
                 if (!$res) {
                     return false;
                 }
             }
         }
     }
     /* Adding non-gettexted strings can repeat some phrases */
     $output_shell = escapeshellarg($output);
     system("msguniq {$output_shell} -o {$output_shell}");
     return $res;
 }
Пример #2
0
 /**
  * POT generator
  *
  * @param string $project "woocommerce" or "woocommerce-admin"
  * @return bool true on success, false on error
  */
 public function generate_pot($project = 'woocommerce')
 {
     // Unknown project
     if (empty($this->projects[$project])) {
         return false;
     }
     // Project config
     $config = $this->projects[$project];
     // Extract translatable strings from the WooCommerce plugin
     $originals = $this->extractor->extract_from_directory($this->woocommerce_path, $config['excludes'], $config['includes']);
     // Build POT file
     $pot = new PO();
     $pot->entries = $originals->entries;
     $pot->set_header('Project-Id-Version', 'WooCommerce ' . $this->woocommerce_version() . ' ' . $config['title']);
     $pot->set_header('Report-Msgid-Bugs-To', 'https://github.com/woothemes/woocommerce/issues');
     $pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
     $pot->set_header('MIME-Version', '1.0');
     $pot->set_header('Content-Type', 'text/plain; charset=UTF-8');
     $pot->set_header('Content-Transfer-Encoding', '8bit');
     $pot->set_header('PO-Revision-Date', gmdate('Y') . '-MO-DA HO:MI+ZONE');
     $pot->set_header('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>');
     $pot->set_header('Language-Team', 'LANGUAGE <EMAIL@ADDRESS>');
     // Write POT file
     $result = $pot->export_to_file($config['file']);
     // Add plugin header
     if ($project == 'woocommerce-admin') {
         $potextmeta = new PotExtMeta();
         $potextmeta->append($this->woocommerce_path . 'woocommerce.php', $config['file']);
     }
     return $result;
 }
    }
    function append($ext_filename, $pot_filename, $headers = null)
    {
        if ($headers) {
            $this->headers = (array) $headers;
        }
        if (is_dir($ext_filename)) {
            $pot = implode('', array_map(array(&$this, 'load_from_file'), glob("{$ext_filename}/*.php")));
        } else {
            $pot = $this->load_from_file($ext_filename);
        }
        $potf = '-' == $pot_filename ? STDOUT : fopen($pot_filename, 'a');
        if (!$potf) {
            return false;
        }
        fwrite($potf, $pot);
        if ('-' != $pot_filename) {
            fclose($potf);
        }
        return true;
    }
}
$included_files = get_included_files();
if ($included_files[0] == __FILE__) {
    ini_set('display_errors', 1);
    $potextmeta = new PotExtMeta();
    if (!isset($argv[1])) {
        $potextmeta->usage();
    }
    $potextmeta->append($argv[1], isset($argv[2]) ? $argv[2] : '-', isset($argv[3]) ? $argv[3] : null);
}
Пример #4
0
 /**
  * Generate a POT file for a theme.
  *
  * @param string $dir Directory to search for gettext calls.
  * @param string $output POT file name.
  * @param string $slug Optional. Theme slug.
  * @param string $excludes Optional. Comma-separated list of exclusion patterns.
  * @param string $includes Optional. Comma-separated list of inclusion patterns.
  * @return bool
  */
 public function wp_theme($dir, $output, $slug = null, $excludes = '', $includes = '')
 {
     if (is_null($slug)) {
         // Guess theme slug.
         $slug = $this->guess_plugin_slug($dir);
     }
     $main_file = $dir . '/style.css';
     $source = $this->get_first_lines($main_file, $this->max_header_lines);
     $excludes = $this->normalize_patterns($excludes);
     $includes = $this->normalize_patterns($includes);
     $output = is_null($output) ? "{$slug}.pot" : $output;
     $placeholders = array();
     $placeholders['version'] = $this->get_addon_header('Version', $source);
     $placeholders['author'] = $this->get_addon_header('Author', $source);
     $placeholders['name'] = $this->get_addon_header('Theme Name', $source);
     $placeholders['slug'] = $slug;
     $license = $this->get_addon_header('License', $source);
     if ($license) {
         $this->meta['wp-theme']['comments'] = "<!=Copyright (C) {year} {author}\nThis file is distributed under the {$license}.=!>";
     } else {
         $this->meta['wp-theme']['comments'] = "<!=Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package.=!>";
     }
     $result = $this->xgettext('wp-theme', $dir, $output, $placeholders, $excludes, $includes);
     if (!$result) {
         return false;
     }
     $potextmeta = new PotExtMeta();
     $result = $potextmeta->append($main_file, $output, array('Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI'));
     if (!$result) {
         return false;
     }
     // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4.
     $extract_templates = !in_array($slug, array('twentyten', 'twentyeleven', 'default', 'classic'));
     if (!$extract_templates) {
         $wp_dir = dirname(dirname(dirname($dir)));
         $extract_templates = file_exists("{$wp_dir}/wp-admin/user/about.php") || !file_exists("{$wp_dir}/wp-load.php");
     }
     if ($extract_templates) {
         $result = $potextmeta->append($dir, $output, array('Template Name'));
         if (!$result) {
             return false;
         }
         $files = scandir($dir);
         foreach ($files as $file) {
             if (in_array($file, array('.', '..', '.git', 'CVS', 'node_modules'))) {
                 continue;
             }
             if (is_dir($dir . '/' . $file)) {
                 $result = $potextmeta->append($dir . '/' . $file, $output, array('Template Name'));
                 if (!$result) {
                     return false;
                 }
             }
         }
     }
     return $result;
 }
Пример #5
0
 /**
  * POT generator
  *
  * @param string $project "redux" or "redux-admin"
  * @return bool true on success, false on error
  */
 public function generate_pot($project = 'redux')
 {
     // Unknown project
     if (empty($this->projects[$project])) {
         return false;
     }
     // Project config
     $config = $this->projects[$project];
     // Extract translatable strings from the ReduxFramework plugin
     $originals = $this->extractor->extract_from_directory($this->redux_path, $config['excludes'], $config['includes']);
     // Build POT file
     $pot = new PO();
     $pot->entries = $originals->entries;
     $pot->set_header('Project-Id-Version', 'Redux Framework ' . $this->redux_version() . ' ' . $config['title']);
     $pot->set_header('Report-Msgid-Bugs-To', 'https://github.com/ReduxFramework/ReduxFramework/issues');
     $pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
     $pot->set_header('MIME-Version', '1.0');
     $pot->set_header('Content-Type', 'text/plain; charset=UTF-8');
     $pot->set_header('Content-Transfer-Encoding', '8bit');
     $pot->set_header('PO-Revision-Date', gmdate('Y') . '-MO-DA HO:MI+ZONE');
     $pot->set_header('Last-Translator', 'Dovy Paukstys <*****@*****.**>');
     $pot->set_header('Language-Team', 'ReduxFramework <*****@*****.**>');
     $pot->set_header('Language', 'en_US');
     $pot->set_header('Plural-Forms', 'nplurals=2; plural=(n != 1);');
     $pot->set_header('esc_html_x;_c;_nc', '');
     $pot->set_header('_nx_noop;_ex;esc_attr__;esc_attr_e;esc_attr_x;esc_html__;esc_html_e;', '');
     $pot->set_header('X-Poedit-KeywordsList', '__;_e;__ngettext;_n;__ngettext_noop;_n_noop;_x;_nx;');
     $pot->set_header('X-Poedit-Basepath', '../../');
     $pot->set_header('X-Poedit-SourceCharset', 'UTF-8');
     $pot->set_header('X-Poedit-SearchPath-0', 'ReduxCore');
     $pot->set_header('X-Poedit-SearchPath-1', 'ReduxCore/languages');
     $pot->set_header('X-Poedit-SearchPath-2', '.');
     // Write POT file
     $result = $pot->export_to_file($config['file']);
     // Add plugin header
     if ($project == 'redux-admin') {
         $potextmeta = new PotExtMeta();
         $potextmeta->append($this->redux_path . 'redux-framework.php', $config['file']);
     }
     return $result;
 }