Update labels for weight units

This commit is contained in:
Corey McKrill 2023-02-02 16:08:44 -08:00
parent cdff039569
commit 54de988f25
No known key found for this signature in database
GPG Key ID: 84BBFE669C4D97B8
10 changed files with 96 additions and 55 deletions

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Admin\Importers
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -482,8 +484,8 @@ class WC_Product_CSV_Importer_Controller {
* @return array
*/
protected function auto_map_columns( $raw_headers, $num_indexes = true ) {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
/*
* @hooked wc_importer_generic_mappings - 10
@ -513,13 +515,13 @@ class WC_Product_CSV_Importer_Controller {
__( 'Low stock amount', 'woocommerce' ) => 'low_stock_amount',
__( 'Sold individually?', 'woocommerce' ) => 'sold_individually',
/* translators: %s: Weight unit */
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight',
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit_label ) => 'weight',
/* translators: %s: Length unit */
sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length',
sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit_label ) => 'length',
/* translators: %s: Width unit */
sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width',
sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit_label ) => 'width',
/* translators: %s: Height unit */
sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height',
sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit_label ) => 'height',
__( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed',
__( 'Purchase note', 'woocommerce' ) => 'purchase_note',
__( 'Sale price', 'woocommerce' ) => 'sale_price',
@ -655,9 +657,9 @@ class WC_Product_CSV_Importer_Controller {
$meta = str_replace( 'meta:', '', $item );
// Available options.
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$options = array(
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$options = array(
'id' => __( 'ID', 'woocommerce' ),
'type' => __( 'Type', 'woocommerce' ),
'sku' => __( 'SKU', 'woocommerce' ),
@ -684,16 +686,16 @@ class WC_Product_CSV_Importer_Controller {
'low_stock_amount' => __( 'Low stock amount', 'woocommerce' ),
'sold_individually' => __( 'Sold individually?', 'woocommerce' ),
/* translators: %s: weight unit */
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ),
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit_label ),
'dimensions' => array(
'name' => __( 'Dimensions', 'woocommerce' ),
'options' => array(
/* translators: %s: dimension unit */
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ),
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit_label ),
/* translators: %s: dimension unit */
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ),
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit_label ),
/* translators: %s: dimension unit */
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ),
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit_label ),
),
),
'category_ids' => __( 'Categories', 'woocommerce' ),

View File

@ -1,4 +1,6 @@
<?php
use Automattic\WooCommerce\Utilities\I18nUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -11,7 +13,11 @@ if ( ! defined( 'ABSPATH' ) ) {
array(
'id' => '_weight',
'value' => $product_object->get_weight( 'edit' ),
'label' => __( 'Weight', 'woocommerce' ) . ' (' . get_option( 'woocommerce_weight_unit' ) . ')',
'label' => sprintf(
/* translators: %s: Weight unit */
__( 'Weight (%s)', 'woocommerce' ),
I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) )
),
'placeholder' => wc_format_localized_decimal( 0 ),
'desc_tip' => true,
'description' => __( 'Weight in decimal form', 'woocommerce' ),

View File

@ -9,6 +9,8 @@
* @var array $variation_data array of variation data @deprecated 4.4.0.
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
defined( 'ABSPATH' ) || exit;
?>
@ -279,9 +281,9 @@ defined( 'ABSPATH' ) || exit;
if ( wc_product_weight_enabled() ) {
$label = sprintf(
/* translators: %s: weight unit */
/* translators: %s: Weight unit */
__( 'Weight (%s)', 'woocommerce' ),
esc_html( get_option( 'woocommerce_weight_unit' ) )
I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) )
);
woocommerce_wp_text_input(

View File

@ -3,6 +3,8 @@
* Admin View: Bulk Edit Products
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
@ -131,7 +133,21 @@ if ( ! defined( 'ABSPATH' ) ) {
</span>
</label>
<label class="change-input">
<input type="text" name="_weight" class="text weight" placeholder="<?php printf( esc_attr__( '%1$s (%2$s)', 'woocommerce' ), wc_format_localized_decimal( 0 ), get_option( 'woocommerce_weight_unit' ) ); ?>" value="">
<?php
$placeholder = sprintf(
/* translators: 1. Weight number; 2. Weight unit; E.g. 2 kg */
__( '%1$s (%2$s)', 'woocommerce' ),
wc_format_localized_decimal( 0 ),
I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) )
);
?>
<input
type="text"
name="_weight"
class="text weight"
placeholder="<?php echo esc_attr( $placeholder ); ?>"
value=""
>
</label>
</div>
<?php endif; ?>

View File

@ -6,6 +6,8 @@
* @version 3.1.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -99,6 +101,9 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* @return array
*/
public function get_default_column_names() {
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
return apply_filters(
"woocommerce_product_export_{$this->export_type}_default_columns",
array(
@ -121,13 +126,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
'backorders' => __( 'Backorders allowed?', 'woocommerce' ),
'sold_individually' => __( 'Sold individually?', 'woocommerce' ),
/* translators: %s: weight */
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), get_option( 'woocommerce_weight_unit' ) ),
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit_label ),
/* translators: %s: length */
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit_label ),
/* translators: %s: width */
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit_label ),
/* translators: %s: Height */
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ),
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit_label ),
'reviews_allowed' => __( 'Allow customer reviews?', 'woocommerce' ),
'purchase_note' => __( 'Purchase note', 'woocommerce' ),
'sale_price' => __( 'Sale price', 'woocommerce' ),

View File

@ -10,6 +10,8 @@
* @since 3.0.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -1728,8 +1730,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
* @return array
*/
public function get_item_schema() {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@ -1985,7 +1987,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -1996,19 +1998,19 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -2438,7 +2440,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -2449,19 +2451,19 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

View File

@ -8,6 +8,8 @@
* @since 3.0.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
defined( 'ABSPATH' ) || exit;
/**
@ -640,8 +642,8 @@ class WC_REST_Product_Variations_V2_Controller extends WC_REST_Products_V2_Contr
* @return array
*/
public function get_item_schema() {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@ -835,7 +837,7 @@ class WC_REST_Product_Variations_V2_Controller extends WC_REST_Products_V2_Contr
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -846,19 +848,19 @@ class WC_REST_Product_Variations_V2_Controller extends WC_REST_Products_V2_Contr
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

View File

@ -8,6 +8,8 @@
* @since 2.6.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
defined( 'ABSPATH' ) || exit;
/**
@ -1663,8 +1665,8 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
* @return array
*/
public function get_item_schema() {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@ -1935,7 +1937,7 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -1946,19 +1948,19 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

View File

@ -8,6 +8,8 @@
* @since 3.0.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
defined( 'ABSPATH' ) || exit;
use Automattic\Jetpack\Constants;
@ -441,8 +443,8 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
* @return array
*/
public function get_item_schema() {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@ -643,7 +645,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -654,19 +656,19 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

View File

@ -8,6 +8,8 @@
* @since 2.6.0
*/
use Automattic\WooCommerce\Utilities\I18nUtil;
defined( 'ABSPATH' ) || exit;
/**
@ -804,8 +806,8 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
* @return array
*/
public function get_item_schema() {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit_label = I18nUtil::get_weight_unit_label( get_option( 'woocommerce_weight_unit', 'kg' ) );
$dimension_unit_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit', 'cm' ) );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@ -1080,7 +1082,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
),
'weight' => array(
/* translators: %s: weight unit */
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ),
'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
@ -1091,19 +1093,19 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
'properties' => array(
'length' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'width' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'height' => array(
/* translators: %s: dimension unit */
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ),
'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit_label ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),