Background of the issue:
I am trying to localize a functions snippet for my site hidden link. The snippet involves a filter for 'woocommerce_shipping_package_name' and a function 'change_shipping_text_to_delivery' that modifies the shipping text to delivery options. The code snippet is: add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 ); function change_shipping_text_to_delivery( $sprintf, $i, $package ) { $sprintf = sprintf( _nx( 'Options de livraison (ajouter 1 à 2 jours de manutention.)', 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) ); return $sprintf; }
Symptoms:
I need help with localizing the snippet for my WordPress site.
Questions:
How can I localize the given functions snippet to make it translatable?
add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 );
function change_shipping_text_to_delivery( $sprintf, $i, $package ) {
$sprintf = sprintf( _nx( _e('Options de livraison (ajouter 1 à 2 jours de manutention.),'woocommerce'), 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) );
return $sprintf;
}
Why: WPML will scan your child theme and register Delivery %d under your domain instead of “woocommerce”.
Step 2: WP Admin → WPML → Theme and plugins localization → scan your child theme.
Step 3: WP Admin → WPML → String Translation → find domain funique-child, translate “Delivery %d” into French (you can drop %d if you don’t need the number, the extra sprintf arg is safely ignored):
Options de livraison (ajouter 1 à 2 jours de manutention.)