I18N: In the POMO library, replace `chr()` calls for static values with their string representation.

Props ccismaru, ocean90.
Fixes #17128.

git-svn-id: https://develop.svn.wordpress.org/trunk@43635 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2018-09-12 06:10:42 +00:00
parent 14d99627ce
commit 82bf9baa32
2 changed files with 12 additions and 12 deletions

View File

@ -81,7 +81,7 @@ if ( ! class_exists( 'Translation_Entry', false ) ) :
}
// Prepend context and EOT, like in MO files
$key = ! $this->context ? $this->singular : $this->context . chr( 4 ) . $this->singular;
$key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular;
// Standardize on \n line endings
$key = str_replace( array( "\r\n", "\r" ), "\n", $key );

View File

@ -124,12 +124,12 @@ if ( ! class_exists( 'MO', false ) ) :
// headers' msgid is an empty string
fwrite( $fh, pack( 'VV', 0, $current_addr ) );
$current_addr++;
$originals_table = chr( 0 );
$originals_table = "\0";
$reader = new POMO_Reader();
foreach ( $entries as $entry ) {
$originals_table .= $this->export_original( $entry ) . chr( 0 );
$originals_table .= $this->export_original( $entry ) . "\0";
$length = $reader->strlen( $this->export_original( $entry ) );
fwrite( $fh, pack( 'VV', $length, $current_addr ) );
$current_addr += $length + 1; // account for the NULL byte after
@ -138,10 +138,10 @@ if ( ! class_exists( 'MO', false ) ) :
$exported_headers = $this->export_headers();
fwrite( $fh, pack( 'VV', $reader->strlen( $exported_headers ), $current_addr ) );
$current_addr += strlen( $exported_headers ) + 1;
$translations_table = $exported_headers . chr( 0 );
$translations_table = $exported_headers . "\0";
foreach ( $entries as $entry ) {
$translations_table .= $this->export_translations( $entry ) . chr( 0 );
$translations_table .= $this->export_translations( $entry ) . "\0";
$length = $reader->strlen( $this->export_translations( $entry ) );
fwrite( $fh, pack( 'VV', $length, $current_addr ) );
$current_addr += $length + 1;
@ -160,10 +160,10 @@ if ( ! class_exists( 'MO', false ) ) :
//TODO: warnings for control characters
$exported = $entry->singular;
if ( $entry->is_plural ) {
$exported .= chr( 0 ) . $entry->plural;
$exported .= "\0" . $entry->plural;
}
if ( $entry->context ) {
$exported = $entry->context . chr( 4 ) . $exported;
$exported = $entry->context . "\4" . $exported;
}
return $exported;
}
@ -174,7 +174,7 @@ if ( ! class_exists( 'MO', false ) ) :
*/
function export_translations( $entry ) {
//TODO: warnings for control characters
return $entry->is_plural ? implode( chr( 0 ), $entry->translations ) : $entry->translations[0];
return $entry->is_plural ? implode( "\0", $entry->translations ) : $entry->translations[0];
}
/**
@ -310,21 +310,21 @@ if ( ! class_exists( 'MO', false ) ) :
*/
function &make_entry( $original, $translation ) {
$entry = new Translation_Entry();
// look for context
$parts = explode( chr( 4 ), $original );
// Look for context, separated by \4.
$parts = explode( "\4", $original );
if ( isset( $parts[1] ) ) {
$original = $parts[1];
$entry->context = $parts[0];
}
// look for plural original
$parts = explode( chr( 0 ), $original );
$parts = explode( "\0", $original );
$entry->singular = $parts[0];
if ( isset( $parts[1] ) ) {
$entry->is_plural = true;
$entry->plural = $parts[1];
}
// plural translations are also separated by \0
$entry->translations = explode( chr( 0 ), $translation );
$entry->translations = explode( "\0", $translation );
return $entry;
}