Improves i18n of string displayed during checkout

This commit improves the i18n of a string displayed during checkout showing the total amount of the order when the store is configured to display prices inclusive of taxes.

Before string concatenation was used to build the final string which is almost always a bad practice from i18n point of view (https://codex.wordpress.org/I18n_for_WordPress_Developers#Best_Practices). This commit uses sprintf() and two separate strings to make translation easier.
This commit is contained in:
Rodrigo Primo 2020-10-22 15:38:07 -03:00
parent 3f61afe533
commit 4e5fb5724c
1 changed files with 10 additions and 9 deletions

View File

@ -316,15 +316,16 @@ function wc_cart_totals_order_total_html() {
if ( ! empty( $tax_string_array ) ) {
$taxable_address = WC()->customer->get_taxable_address();
/* translators: %s: country name */
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping() ? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] ) : '';
$value .= '<small class="includes_tax">('
/* translators: includes tax information */
. esc_html__( 'includes', 'woocommerce' )
. ' '
. wp_kses_post( implode( ', ', $tax_string_array ) )
. esc_html( $estimated_text )
. ')</small>';
if ( WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping() ) {
$country = WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ];
/* translators: 1: tax amount 2: country name */
$tax_text = wp_kses_post( sprintf( __( '(includes %1$s estimated for %2$s)', 'woocommerce' ), implode( ', ', $tax_string_array ), $country ) );
} else {
/* translators: %s: tax amount */
$tax_text = wp_kses_post( sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) );
}
$value .= '<small class="includes_tax">' . $tax_text . '</small>';
}
}