Make WordPress Core

Ticket #34749: 34749-develop-svn.diff

File 34749-develop-svn.diff, 5.4 KB (added by netweb, 8 years ago)
  • tools/i18n/makepot.php

     
    2626                'glotpress',
    2727                'rosetta',
    2828                'wporg-bb-forums',
     29                'wporg-themes',
     30                'wporg-plugins',
     31                'wporg-forums',
     32                'wordcamporg',
    2933        );
    3034
    3135        var $rules = array(
     
    137141                        'copyright-holder' => 'WordPress',
    138142                        'package-name' => 'WordPress.org International Forums',
    139143                ),
     144                'wporg' => array(
     145                        'description' => 'WordPress.org',
     146                        'copyright-holder' => 'WordPress',
     147                        'package-name' => 'WordPress.org',
     148                ),
     149                'wordcamporg' => array(
     150                        'description' => 'WordCamp.org',
     151                        'copyright-holder' => 'WordPress',
     152                        'package-name' => 'WordCamp.org',
     153                ),
    140154                'rosetta' => array(
    141155                        'description' => 'Rosetta (.wordpress.org locale sites)',
    142156                        'copyright-holder' => 'WordPress',
     
    408422                return $this->xgettext('wp', $dir, $output, $placeholders);
    409423        }
    410424
    411 
    412         function bb($dir, $output) {
    413                 $placeholders = array();
    414                 $output = is_null($output)? 'bbpress.pot' : $output;
    415                 return $this->xgettext('bb', $dir, $output, $placeholders);
    416 
    417         }
    418 
    419425        function get_first_lines($filename, $lines = 30) {
    420426                $extf = fopen($filename, 'r');
    421427                if (!$extf) return false;
     
    428434                        }
    429435                        $first_lines .= $line;
    430436                }
     437
     438                // PHP will close file handle, but we are good citizens.
     439                fclose( $extf );
     440
     441                // Make sure we catch CR-only line endings.
     442                $first_lines = str_replace( "\r", "\n", $first_lines );
     443
    431444                return $first_lines;
    432445        }
    433446
    434 
    435447        function get_addon_header($header, &$source) {
    436                 if (preg_match('|'.$header.':(.*)$|mi', $source, $matches))
    437                         return trim($matches[1]);
    438                 else
     448                /*
     449                 * A few things this needs to handle:
     450                 * - 'Header: Value\n'
     451                 * - '// Header: Value'
     452                 * - '/* Header: Value * /'
     453                 * - '<?php // Header: Value ?>'
     454                 * - '<?php /* Header: Value * / $foo='bar'; ?>'
     455                 */
     456                if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $header, '/' ) . ':(.*)$/mi', $source, $matches ) ) {
     457                        return $this->_cleanup_header_comment( $matches[1] );
     458                } else {
    439459                        return false;
     460                }
    440461        }
    441462
     463        /**
     464         * Removes any trailing closing comment / PHP tags from the header value
     465         */
     466        function _cleanup_header_comment( $str ) {
     467                return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) );
     468        }
     469
    442470        function generic($dir, $output) {
    443471                $output = is_null($output)? "generic.pot" : $output;
    444472                return $this->xgettext('generic', $dir, $output, array());
     
    455483                return $slug;
    456484        }
    457485
    458         function wp_plugin($dir, $output, $slug = null) {
     486        function wp_plugin( $dir, $output, $slug = null, $args = array() ) {
     487                $defaults = array(
     488                        'excludes' => array(),
     489                        'includes' => array(),
     490                );
     491                $args = array_merge( $defaults, $args );
    459492                $placeholders = array();
    460493                // guess plugin slug
    461494                if (is_null($slug)) {
     
    506539                $placeholders['slug'] = $slug;
    507540
    508541                $output = is_null($output)? "$slug.pot" : $output;
    509                 $res = $this->xgettext('wp-plugin', $dir, $output, $placeholders);
     542                $res = $this->xgettext( 'wp-plugin', $dir, $output, $placeholders, $args['excludes'], $args['includes'] );
    510543                if (!$res) return false;
    511544                $potextmeta = new PotExtMeta;
    512545                $res = $potextmeta->append($main_file, $output);
     
    571604                return $res;
    572605        }
    573606
    574         function bp($dir, $output) {
    575                 $output = is_null($output)? "buddypress.pot" : $output;
    576                 return $this->xgettext('bp', $dir, $output, array(), array('bp-forums/bbpress/.*'));
     607        function bp( $dir, $output ) {
     608                $output = is_null( $output ) ? 'buddypress.pot' : $output;
     609                $args = array(
     610                        'excludes' => array( 'bp-forums/bbpress/.*', 'tests/.*' ),
     611                );
     612
     613                // BuddyPress 2.1+
     614                if ( is_dir( "$dir/src" ) ) {
     615                        $args = array(
     616                                'includes' => array( 'src/.*' ),
     617                                'excludes' => array( 'src/bp-forums/bbpress/.*' ),
     618                        );
     619                }
     620
     621                return $this->wp_plugin( $dir, $output, 'buddypress', $args );
    577622        }
    578623
     624        function bb( $dir, $output ) {
     625                $output = is_null( $output ) ? 'bbpress.pot' : $output;
     626                return $this->wp_plugin( $dir, $output, 'bbpress' );
     627        }
     628
    579629        function glotpress( $dir, $output ) {
    580630                $output = is_null( $output ) ? "glotpress.pot" : $output;
    581631                return $this->xgettext( 'glotpress', $dir, $output );
     
    586636                return $this->xgettext( 'wporg-bb-forums', $dir, $output, array(), array(
    587637                        'bb-plugins/elfakismet/.*',
    588638                        'bb-plugins/support-forum/.*',
     639                        'themes/.*',
    589640                ) );
    590641        }
    591642
     643        function wporg_themes( $dir, $output ) {
     644                $output = is_null( $output ) ? 'wporg-themes.pot' : $output;
     645                return $this->xgettext( 'wporg', $dir, $output, array(), array(), array(
     646                        'plugins/theme-directory/.*',
     647                        'themes/pub/wporg-themes/.*'
     648                ) );
     649        }
     650
     651        function wporg_plugins( $dir, $output ) {
     652                $output = is_null( $output ) ? 'wporg-plugins.pot' : $output;
     653                return $this->xgettext( 'wporg', $dir, $output, array(), array(), array(
     654                        '.*\.php',
     655                ) );
     656        }
     657
     658        function wporg_forums( $dir, $output ) {
     659                $output = is_null( $output ) ? 'wporg-forums.pot' : $output;
     660                return $this->xgettext( 'wporg', $dir, $output, array(), array(), array(
     661                        '.*\.php',
     662                ) );
     663        }
     664
     665        function wordcamporg( $dir, $output ) {
     666                $output = is_null( $output ) ? 'wordcamporg.pot' : $output;
     667                return $this->xgettext( 'wordcamporg', $dir, $output, array(), array(), array(
     668                        '.*\.php',
     669                ) );
     670        }
     671
    592672        function rosetta( $dir, $output ) {
    593673                $output = is_null( $output )? 'rosetta.pot' : $output;
    594674                return $this->xgettext( 'rosetta', $dir, $output, array(), array(), array(