Making WordPress.org

Changeset 7895


Ignore:
Timestamp:
11/24/2018 03:13:59 PM (6 years ago)
Author:
ocean90
Message:

Translate, Theme Directory: Use wp i18n make-pot for string extraction.

Props herregroen, ocean90.
See #3748.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php

    r7338 r7895  
    33namespace WordPressdotorg\GlotPress\Theme_Directory\CLI;
    44
     5use Exception;
    56use GP;
    67use MakePOT;
     
    2526    private $temp_dir;
    2627
    27     /**
    28      * MakePot instance.
    29      *
    30      * @var MakePot
    31      */
    32     private $makepot;
    33 
    3428    public function __construct() {
    3529        if ( ! file_exists( '/tmp/wporg-themes-i18n/' ) ) {
     
    4236            WP_CLI::error( "Couldn't create temporary directory." );
    4337        }
    44 
    45         $this->checkout_tools();
    46         if ( ! file_exists( $this->temp_dir . '/i18n-tools/makepot.php' ) ) {
    47             WP_CLI::error( "Couldn't find MakePot." );
    48         }
    49         require_once $this->temp_dir . '/i18n-tools/makepot.php';
    50         $this->makepot = new MakePot();
    5138    }
    5239
     
    8269
    8370        $project = $this->find_create_update_glotpress_project( $theme_slug, $theme_data );
    84         $pot = $this->generate_pot( $theme_slug, $theme_dir );
     71
     72        try {
     73            $pot = $this->generate_pot( $theme_slug, $theme_dir );
     74        } catch ( Exception $exception ) {
     75            $this->cleanup_theme( $theme_slug );
     76            WP_CLI::error( "{$theme_slug} {$theme_version} not imported: " . $exception->getMessage() );
     77        }
     78
    8579        $this->import_pot_to_glotpress( $pot, $project );
    8680
     
    157151     */
    158152    private function generate_pot( $theme_slug, $theme_dir ) {
     153        if ( ! defined( 'WPORGTRANSLATE_WPCLI' ) ) {
     154            throw new Exception( 'Missing configuration for WPORGTRANSLATE_WPCLI.' );
     155        }
     156
    159157        $pot_file = "{$this->temp_dir}/{$theme_slug}.pot";
    160         $this->makepot->wp_theme( $theme_dir, $pot_file );
     158
     159        $cmd = sprintf(
     160            '%s i18n make-pot %s %s --slug=%s --ignore-domain --skip-audit',
     161            WPORGTRANSLATE_WPCLI,
     162            escapeshellarg( $theme_dir ),
     163            escapeshellarg( $pot_file ),
     164            escapeshellarg( $theme_slug )
     165        );
     166
     167        exec( $cmd, $output, $return_code );
     168
     169        if ( 0 !== $return_code || ! file_exists( $pot_file ) ) {
     170            throw new Exception( "POT file couldn't be created." );
     171        }
     172
    161173        return $pot_file;
    162174    }
     
    178190            'description'         => $theme_data['description'] . "<br><br><a href='https://wordpress.org/themes/{$theme_slug}'>WordPress.org Theme Page</a>",
    179191            'parent_project_id'   => $parent_project->id,
    180             'source_url_template' => "https://themes.trac.wordpress.org/browser/$theme_slug/{$theme_data['version']}/%file%#L%line%",
     192            'source_url_template' => "https://themes.trac.wordpress.org/browser/$theme_slug/{$theme_data['version']}/%file%?marks=%line%#L%line%",
    181193            'active'              => 1,
    182194        );
     
    290302        $priorities = array(
    291303            // These are important strings that we need translated
    292             'Plugin Name of the plugin/theme' => 1,
    293             'Theme Name of the plugin/theme'  => 1,
    294             'Description of the plugin/theme' => 1,
     304            'Theme Name of the theme'  => 1,
     305            'Description of the theme' => 1,
    295306            // Regular strings are more important than these:
    296             'Plugin URI of the plugin/theme'  => -1,
    297             'Theme URI of the plugin/theme'   => -1,
    298             'Author of the plugin/theme'      => -1,
    299             'Author URI of the plugin/theme'  => -1,
     307            'Theme URI of the theme'   => -1,
     308            'Author of the theme'      => -1,
     309            'Author URI of the theme'  => -1,
    300310        );
     311
    301312        if ( isset( $priorities[ $data['comment'] ] ) ) {
    302313            $data['priority'] = $priorities[ $data['comment'] ];
    303         }
     314        } else {
     315            $data['priority'] = 0;
     316        }
     317
    304318        return $data;
    305     }
    306 
    307     /**
    308      * Creates an i18n-tools checkout so we have MakePot available.
    309      */
    310     private function checkout_tools() {
    311         $tools_dir = "{$this->temp_dir}/i18n-tools/";
    312         if ( ! file_exists( $tools_dir ) ) {
    313             $esc_tools_dir = escapeshellarg( $tools_dir );
    314             `svn export --non-interactive https://i18n.svn.wordpress.org/tools/trunk {$esc_tools_dir}`;
    315         }
    316319    }
    317320
Note: See TracChangeset for help on using the changeset viewer.