[wp-trac] [WordPress Trac] #60678: Definition of WP_Translation_File_MO::MAGIC_MARKER

WordPress Trac noreply at wordpress.org
Sun Mar 3 14:43:12 UTC 2024


#60678: Definition of WP_Translation_File_MO::MAGIC_MARKER
--------------------------+-----------------------------
 Reporter:  tmatsuur      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Currently some PHP environments may fail to load mo files.

 The environment in which this problem occurred:

 {{{
 PHP 7.4.32 (cli) (built: Sep 28 2022 20:48:52) ( ZTS Visual C++ 2017 x86 )
 }}}

 I investigated the cause and found that it was due to the definition of
 class constants.

 {{{
 const MAGIC_MARKER = 0x950412de;
 }}}

 Dumping this constant:

 {{{
 var_dump( WP_Translation_File_MO::MAGIC_MARKER );

 :

 float(2500072158)
 }}}


 Due to the data type of the constant being "float" instead of "int", the
 detect_endian_and_validate_file method was returning false when reading
 the .mo file.

 As a temporary measure, the WP_Translation_File_MO class has been changed
 as follows:

 {{{
 const MAGIC_MARKER = '0x950412de';

 :

 protected function detect_endian_and_validate_file( string $header ) {

 :

         if ( (int)hexdec( self::MAGIC_MARKER ) === $big ) {
                 return 'N';
         }

         if ( (int)hexdec( self::MAGIC_MARKER ) === $little ) {
                 return 'V';
         }
 }}}

 This way, the mo file can be read and the translated content will be
 reflected.

 I'm sure there are more appropriate ways to correct this, but I hope this
 helps.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60678>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list