i18n tools: Improve support for multi-line comments in StringExtractor.
props SergeyBiryukov. fixes #30972. git-svn-id: https://develop.svn.wordpress.org/trunk@31498 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7f69e6430b
commit
684b992597
@ -170,6 +170,8 @@ class StringExtractor {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( T_COMMENT == $id ) {
|
if ( T_COMMENT == $id ) {
|
||||||
|
$text = preg_replace( '%^\s+\*\s%m', '', $text );
|
||||||
|
$text = str_replace( array( "\r\n", "\n" ), ' ', $text );;
|
||||||
$text = trim( preg_replace( '%^/\*|//%', '', preg_replace( '%\*/$%', '', $text ) ) );
|
$text = trim( preg_replace( '%^/\*|//%', '', preg_replace( '%\*/$%', '', $text ) ) );
|
||||||
if ( 0 === stripos( $text, $this->comment_prefix ) ) {
|
if ( 0 === stripos( $text, $this->comment_prefix ) ) {
|
||||||
$latest_comment = $text;
|
$latest_comment = $text;
|
||||||
|
@ -134,27 +134,62 @@ class ExtractTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( g( "dyado", "chicho", "lelya "), "baba" ); ' ) );
|
$this->assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( g( "dyado", "chicho", "lelya "), "baba" ); ' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
function test_find_function_calls_with_comment() {
|
function test_find_function_calls_with_comment() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
||||||
$this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ' ) );
|
$this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ' )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
function test_find_function_calls_with_not_immediate_comment() {
|
function test_find_function_calls_with_not_immediate_comment() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
||||||
$this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ' ) );
|
$this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ' )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
function test_find_function_calls_with_not_immediate_comment_include_only_latest() {
|
function test_find_function_calls_with_not_immediate_comment_include_only_latest() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ),
|
||||||
$this->extractor->find_function_calls( array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ' ) );
|
$this->extractor->find_function_calls( array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ' )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
|
function test_find_function_calls_with_multi_line_comment() {
|
||||||
|
$this->assertEquals( array( array(
|
||||||
|
'name' => '__', 'args' => array( 'on' ), 'line' => 6,
|
||||||
|
'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."
|
||||||
|
) ),
|
||||||
|
$this->extractor->find_function_calls( array( '__' ),
|
||||||
|
"<?php
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
__( 'on' );"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
function test_comment_prefix_should_be_case_insensitive() {
|
function test_comment_prefix_should_be_case_insensitive() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'Translators: let your ears fly!' ) ),
|
array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'Translators: let your ears fly!' ) ),
|
||||||
$this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' ) );
|
$this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user