Make WordPress Core

Ticket #43864: extract-inline-translator-comments.patch

File extract-inline-translator-comments.patch, 2.4 KB (added by julesaus, 8 years ago)

Patch

  • tools/i18n/extract.php

     
    174174                                $text = str_replace( array( "\r\n", "\n" ), ' ', $text );;
    175175                                $text = trim( preg_replace( '%^(/\*|//)%', '', preg_replace( '%\*/$%', '', $text ) ) );
    176176                                if ( 0 === stripos( $text, $this->comment_prefix ) ) {
     177                                  if ( $in_func ) {
     178                                        $func_comment = $text;
     179                                  } else {
    177180                                        $latest_comment = $text;
     181                                  }
    178182                                }
     183                                continue;
    179184                        }
    180185                        if ( !$in_func ) continue;
    181186                        if ( '(' == $token ) {
  • tools/i18n/t/ExtractTest.php

     
    224224                        $this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' )
    225225                );
    226226        }
     227
     228        /**
     229         * @group comment
     230         */
     231        function test_find_function_calls_with_inline_c_style_comment() {
     232                $this->assertEquals( array( array(
     233                                'name' => '__', 'args' => array( 'on' ), 'line' => 2,
     234                        ) ),
     235                        $this->extractor->find_function_calls( array( '__' ),
     236                                "<?php
     237                                __( // unrelated comment
     238                                'on' );"
     239                        )
     240                );
     241                $this->assertEquals( array( array(
     242                                'name' => '_n', 'args' => array( '1 thought', '%d thoughts' ), 'line' => 2,
     243                        ) ),
     244                        $this->extractor->find_function_calls( array( '_n' ),
     245                                "<?php
     246                                _n( // unrelated comment
     247                                '1 thought',
     248                                '%d thoughts'
     249                                 );"
     250                        )
     251                );
     252        }
     253
     254        /**
     255         * @group comment
     256         */
     257        function test_find_function_calls_with_inline_c_style_translator_comment() {
     258                $this->assertEquals( array( array(
     259                        'name' => '__', 'args' => array( 'on' ), 'line' => 2,
     260                        'comment' => "translators: I'd hate for you to miss helpful comments",
     261                ) ),
     262                        $this->extractor->find_function_calls( array( '__' ),
     263                                "<?php
     264                                __( // translators: I'd hate for you to miss helpful comments
     265                                'on' );"
     266                        )
     267                );
     268                $this->assertEquals( array( array(
     269                        'name' => '_n', 'args' => array( '1 thought', '%d thoughts' ), 'line' => 2,
     270                        'comment' => "translators: I'd hate for you to miss helpful comments",
     271                ) ),
     272                        $this->extractor->find_function_calls( array( '_n' ),
     273                                "<?php
     274                                _n( // translators: I'd hate for you to miss helpful comments
     275                                '1 thought',
     276                                '%d thoughts'
     277                                 );"
     278                        )
     279                );
     280        }
    227281}