Make WordPress Core

Changeset 31498


Ignore:
Timestamp:
02/22/2015 12:46:12 PM (10 years ago)
Author:
ocean90
Message:

i18n tools: Improve support for multi-line comments in StringExtractor.

props SergeyBiryukov.
fixes #30972.

Location:
trunk/tools/i18n
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/i18n/extract.php

    r29563 r31498  
    171171            }
    172172            if ( T_COMMENT == $id ) {
     173                $text = preg_replace( '%^\s+\*\s%m', '', $text );
     174                $text = str_replace( array( "\r\n", "\n" ), ' ', $text );;
    173175                $text = trim( preg_replace( '%^/\*|//%', '', preg_replace( '%\*/$%', '', $text ) ) );
    174176                if ( 0 === stripos( $text, $this->comment_prefix ) ) {
  • trunk/tools/i18n/t/ExtractTest.php

    r25920 r31498  
    135135    }
    136136
     137    /**
     138     * @group comment
     139     */
    137140    function test_find_function_calls_with_comment() {
    138141        $this->assertEquals(
    139142            array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
    140             $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ' ) );
     143            $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ' )
     144        );
    141145    }
    142146
     147    /**
     148     * @group comment
     149     */
    143150    function test_find_function_calls_with_not_immediate_comment() {
    144151        $this->assertEquals(
    145152            array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
    146             $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ' ) );
     153            $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ' )
     154        );
    147155    }
    148156
     157    /**
     158     * @group comment
     159     */
    149160    function test_find_function_calls_with_not_immediate_comment_include_only_latest() {
    150161        $this->assertEquals(
    151162            array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
    152             $this->extractor->find_function_calls( array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ' ) );
     163            $this->extractor->find_function_calls( array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ' )
     164        );
    153165    }
    154166
     167    /**
     168     * @group comment
     169     */
     170    function test_find_function_calls_with_multi_line_comment() {
     171        $this->assertEquals( array( array(
     172                'name' => '__', 'args' => array( 'on' ), 'line' => 6,
     173                'comment' => "Translators: If there are characters in your language that are not supported by Lato, translate this to 'off'. Do not translate into your own language."
     174            ) ),
     175            $this->extractor->find_function_calls( array( '__' ),
     176                "<?php
     177                /*
     178                 * Translators: If there are characters in your language that are not supported
     179                 * by Lato, translate this to 'off'. Do not translate into your own language.
     180                 */
     181                __( 'on' );"
     182            )
     183        );
     184    }
     185
     186    /**
     187     * @group comment
     188     */
    155189    function test_comment_prefix_should_be_case_insensitive() {
    156190        $this->assertEquals(
    157191            array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'Translators: let your ears fly!' ) ),
    158             $this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' ) );
     192            $this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' )
     193        );
    159194    }
    160195}
Note: See TracChangeset for help on using the changeset viewer.