From d6ff006ec49576a622d7befa57614f54bbd9aee1 Mon Sep 17 00:00:00 2001 From: Nicolas Juen Date: Sun, 17 May 2020 17:48:10 +0200 Subject: [PATCH 1/5] Translate size units in size_format --- src/wp-includes/functions.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 4a92e3ed8a95f..bebdc36df103f 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -450,15 +450,21 @@ function number_format_i18n( $number, $decimals = 0 ) { */ function size_format( $bytes, $decimals = 0 ) { $quant = array( - 'TB' => TB_IN_BYTES, - 'GB' => GB_IN_BYTES, - 'MB' => MB_IN_BYTES, - 'KB' => KB_IN_BYTES, - 'B' => 1, + /* translators: File size in terabytes. */ + __( 'TB' ) => TB_IN_BYTES, + /* translators: File size in gigabytes. */ + __( 'GB' ) => GB_IN_BYTES, + /* translators: File size in megabytes. */ + __( 'MB' ) => MB_IN_BYTES, + /* translators: File size in kilobytes. */ + __( 'KB' ) => KB_IN_BYTES, + /* translators: File size in bytes. */ + __( 'B' ) => 1, ); if ( 0 === $bytes ) { - return number_format_i18n( 0, $decimals ) . ' B'; + /* translators: File size in bytes. */ + return number_format_i18n( 0, $decimals ) . __( ' B' ); } foreach ( $quant as $unit => $mag ) { From 646981b6c347c703d9b9e658e2d3aa62c87cd977 Mon Sep 17 00:00:00 2001 From: Nicolas Juen Date: Sun, 17 May 2020 17:48:41 +0200 Subject: [PATCH 2/5] Translate units into wp_convert_bytes_to_hr --- src/wp-includes/deprecated.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 643a0bc7f5d1b..1ae158f37574f 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -3340,7 +3340,18 @@ function gd_edit_image_support($mime_type) { function wp_convert_bytes_to_hr( $bytes ) { _deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' ); - $units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' ); + $units = array( + /* translators: File size in bytes. */ + 0 => __( 'B' ), + /* translators: File size in kilobytes. */ + 1 => __( 'KB' ), + /* translators: File size in megabytes. */ + 2 => __( 'MB' ), + /* translators: File size in gigabytes. */ + 3 => __( 'GB' ), + /* translators: File size in terabytes. */ + 4 => __( 'TB' ), + ); $log = log( $bytes, KB_IN_BYTES ); $power = (int) $log; $size = KB_IN_BYTES ** ( $log - $power ); From c939072a120ffcba6f3a6e771478123c8d8b6680 Mon Sep 17 00:00:00 2001 From: Nicolas Juen Date: Mon, 18 May 2020 09:13:39 +0200 Subject: [PATCH 3/5] Add precise ocmment when 0 bytes --- src/wp-includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index bebdc36df103f..b8f7141fbff76 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -463,7 +463,7 @@ function size_format( $bytes, $decimals = 0 ) { ); if ( 0 === $bytes ) { - /* translators: File size in bytes. */ + /* translators: File size in bytes when 0 bytes. */ return number_format_i18n( 0, $decimals ) . __( ' B' ); } From 92c07dc4fb6f8ddd3f6b4ed897d8c9b81b403cf9 Mon Sep 17 00:00:00 2001 From: Nicolas Juen Date: Mon, 18 May 2020 10:25:19 +0200 Subject: [PATCH 4/5] Use _x functions for context, remove trailing space on translation, change translator comment --- src/wp-includes/deprecated.php | 20 ++++++++++---------- src/wp-includes/functions.php | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 1ae158f37574f..5d597c51ae3e3 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -3341,16 +3341,16 @@ function wp_convert_bytes_to_hr( $bytes ) { _deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' ); $units = array( - /* translators: File size in bytes. */ - 0 => __( 'B' ), - /* translators: File size in kilobytes. */ - 1 => __( 'KB' ), - /* translators: File size in megabytes. */ - 2 => __( 'MB' ), - /* translators: File size in gigabytes. */ - 3 => __( 'GB' ), - /* translators: File size in terabytes. */ - 4 => __( 'TB' ), + /* translators: Unit symbol for byte. */ + 0 => _x( 'B', 'unit symbol' ), + /* translators: Unit symbol for kilobyte. */ + 1 => _x( 'KB', 'unit symbol' ), + /* translators: Unit symbol for megabyte. */ + 2 => _x( 'MB', 'unit symbol' ), + /* translators: Unit symbol for gigabyte. */ + 3 => _x( 'GB', 'unit symbol' ), + /* translators: Unit symbol for terabyte. */ + 4 => _x( 'TB', 'unit symbol' ), ); $log = log( $bytes, KB_IN_BYTES ); $power = (int) $log; diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index b8f7141fbff76..83e59b8812e87 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -450,21 +450,21 @@ function number_format_i18n( $number, $decimals = 0 ) { */ function size_format( $bytes, $decimals = 0 ) { $quant = array( - /* translators: File size in terabytes. */ - __( 'TB' ) => TB_IN_BYTES, - /* translators: File size in gigabytes. */ - __( 'GB' ) => GB_IN_BYTES, - /* translators: File size in megabytes. */ - __( 'MB' ) => MB_IN_BYTES, - /* translators: File size in kilobytes. */ - __( 'KB' ) => KB_IN_BYTES, - /* translators: File size in bytes. */ - __( 'B' ) => 1, + /* translators: Unit symbol for terabyte. */ + _x( 'TB', 'unit symbol' ) => TB_IN_BYTES, + /* translators: Unit symbol for gigabyte. */ + _x( 'GB', 'unit symbol' ) => GB_IN_BYTES, + /* translators: Unit symbol for megabyte. */ + _x( 'MB', 'unit symbol' ) => MB_IN_BYTES, + /* translators: Unit symbol for kilobyte. */ + _x( 'KB', 'unit symbol' ) => KB_IN_BYTES, + /* translators: Unit symbol for byte. */ + _x( 'B', 'unit symbol' ) => 1, ); if ( 0 === $bytes ) { - /* translators: File size in bytes when 0 bytes. */ - return number_format_i18n( 0, $decimals ) . __( ' B' ); + /* translators: Unit symbol for byte. */ + return number_format_i18n( 0, $decimals ) . ' ' . _x( 'B', 'unit symbol' ); } foreach ( $quant as $unit => $mag ) { From e25b152147253d65a7f4ff79b8e5f063c361e57a Mon Sep 17 00:00:00 2001 From: Nicolas Juen Date: Wed, 20 May 2020 09:18:26 +0200 Subject: [PATCH 5/5] Restore current wp_convert_bytes_to_hr function --- src/wp-includes/deprecated.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 5d597c51ae3e3..643a0bc7f5d1b 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -3340,18 +3340,7 @@ function gd_edit_image_support($mime_type) { function wp_convert_bytes_to_hr( $bytes ) { _deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' ); - $units = array( - /* translators: Unit symbol for byte. */ - 0 => _x( 'B', 'unit symbol' ), - /* translators: Unit symbol for kilobyte. */ - 1 => _x( 'KB', 'unit symbol' ), - /* translators: Unit symbol for megabyte. */ - 2 => _x( 'MB', 'unit symbol' ), - /* translators: Unit symbol for gigabyte. */ - 3 => _x( 'GB', 'unit symbol' ), - /* translators: Unit symbol for terabyte. */ - 4 => _x( 'TB', 'unit symbol' ), - ); + $units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' ); $log = log( $bytes, KB_IN_BYTES ); $power = (int) $log; $size = KB_IN_BYTES ** ( $log - $power );