Skip to content
Permalink
Browse files

Add multiline comment support (#990)

  • Loading branch information...
akirk authored and ocean90 committed Mar 27, 2019
1 parent 0dd9c9f commit ad0112c809e253c16091fc321a7ea3fe021d21f5
@@ -107,13 +107,22 @@ public function read_originals_from_file( $file_name ) {
$file = mb_convert_encoding( $file, 'UTF-8', 'UTF-16LE' );
}
// Convert multi-line comments into a single line.
$file = preg_replace_callback(
'/\/\*\s*(.*?)\s*\*\//s',
function( $m ) {
return str_replace( PHP_EOL, '\n', $m[0] );
},
$file
);
$context = $comment = null;
$lines = explode( "\n", $file );
foreach ( $lines as $line ) {
if ( is_null( $context ) ) {
if ( preg_match( '/^\/\*\s*(.*)\s*\*\/$/', $line, $matches ) ) {
$matches[1] = trim( $matches[1] );
$matches[1] = trim( str_replace( '\n', PHP_EOL, $matches[1] ) );
if ( $matches[1] !== "No comment provided by engineer." ) {
$comment = $matches[1];
Binary file not shown.
@@ -20,4 +20,10 @@
"me & you are not &" = "me & you are not &";

/* Me, myself & Irene */
"baba" = "baba";
"baba" = "baba";

/* This is
a multiline
comment which is
also supposed to work. */
"multiline" = "multiline";
@@ -1,4 +1,4 @@
/* Translation-Revision-Date: +0000 */
/* Translation-Revision-Date: +0000 */
/* Plural-Forms: nplurals=2; plural=n != 1; */
/* Generator: GlotPress/[GP VERSION] */
/* Language: en_US */
@@ -21,6 +21,12 @@
/* No comment provided by engineer. */
"me > you" = "аз > ти";

/* This is
a multiline
comment which is
also supposed to work. */
"multiline" = "multiline";

/* No comment provided by engineer. */
"you < me" = "ти < аз";

@@ -14,6 +14,10 @@ function setUp() {
array('me > you', 'me > you', "аз > ти", ''),
array('me & you are not &amp;', 'me & you are not &amp;', 'аз & ти не сме &amp;', ''),
array('baba', 'baba', 'баба', 'Me, myself & Irene'),
array('multiline', 'multiline', 'multiline', 'This is
a multiline
comment which is
also supposed to work.'),
);
}
@@ -36,6 +40,8 @@ function test_export() {
$file_contents = file_get_contents( GP_DIR_TESTDATA . '/translation.strings' );
$file_contents = str_replace( '[GP VERSION]', GP_VERSION, $file_contents );
// Remove the UTF-8 Byte Order Mark which is necessary to ensure a UTF-8 detection of the file.
$file_contents = substr( $file_contents, 3 );
$exported = $this->strings->print_exported_file( $project, $locale, $set, $entries_for_export );

0 comments on commit ad0112c

Please sign in to comment.
You can’t perform that action at this time.