Update weight/dim formatting to use translated labels

This commit is contained in:
Corey McKrill 2023-01-31 17:14:07 -08:00
parent 21bae97e82
commit 45069b1bf7
No known key found for this signature in database
GPG Key ID: 84BBFE669C4D97B8
1 changed files with 17 additions and 2 deletions

View File

@ -8,6 +8,7 @@
* @version 2.1.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
use Automattic\WooCommerce\Utilities\NumberUtil;
defined( 'ABSPATH' ) || exit;
@ -1303,7 +1304,14 @@ function wc_format_weight( $weight ) {
$weight_string = wc_format_localized_decimal( $weight );
if ( ! empty( $weight_string ) ) {
$weight_string .= ' ' . get_option( 'woocommerce_weight_unit' );
$weight_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit' ) );
$weight_string = sprintf(
// translators: 1. A formatted number; 2. A label for a weight unit of measure. E.g. 2.72 kg
_x( '%1$s %2$s', 'formatted weight', 'woocommerce' ),
$weight_string,
$weight_label
);
} else {
$weight_string = __( 'N/A', 'woocommerce' );
}
@ -1322,7 +1330,14 @@ function wc_format_dimensions( $dimensions ) {
$dimension_string = implode( ' × ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );
if ( ! empty( $dimension_string ) ) {
$dimension_string .= ' ' . get_option( 'woocommerce_dimension_unit' );
$dimension_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit' ) );
$dimension_string = sprintf(
// translators: 1. A formatted number; 2. A label for a dimensions unit of measure. E.g. 3.14 cm
_x( '%1$s %2$s', 'formatted dimensions', 'woocommerce' ),
$dimension_string,
$dimension_label
);
} else {
$dimension_string = __( 'N/A', 'woocommerce' );
}