Archived topic
Translate Banner after "Add to cart"
14 replies · Started by nik9 on August 18, 2020
Hello,
I'm trying to translate the added to cart banner text to German. Unfortunately it's not translated by default and with loco translate I do not find any value for this.
Printscreen: https://ibb.co/PWZDXC2
I was sure that this is Coming from WooCommerce but now I think it's Coming from GP? Is this right?
I'm playing around with the following code but no change at all:
add_filter( 'wc_add_to_cart_message_html', 'my_changed_wc_add_to_cart_message_html', 10, 2 );
function my_changed_wc_add_to_cart_message_html($message, $products){
if (strpos($message, 'Continue shopping') !== false) {
$message = str_replace("Continue shoppindddg", "Go the checkout", $message);
}
return $message;
}
There are actually 3 values to translate:
- Continue Shopping
- Item added to cart
- Item
When this is Coming from GP, how can I adjust the values? :)
Cheers
Hi there,
thats is a translatable string - i assume its not being included in the German translation yet.
You can try the gettext filter:
add_filter( 'gettext', function( $translated_text ) {
if ( 'Continue shopping' === $translated_text ) {
$translated_text = 'Your new text here';
}
return $translated_text;
} );
Hi Dave,
But is this coming from GP? Because it's not only "Continue Shopping" wrong. Also "Item added to cart" and "Item" are in the wrong language.
So your filter works. But we had to this also for the others like "Item added to cart" and "Item" from this banner..
Cheers
Yes, its a GP template.
But it is output as a translatable string:
https://developer.wordpress.org/reference/functions/_e/
So it should grab the local variant - i can only assume it doesn't exist.
I'll pass this onto Tom to get his input.
Okey, Thanks.
Waiting for toms answer :)
Cheers
Hi there,
May be worth checking with Loco Translate. The strings should be translatable:
_e( 'Continue Shopping', 'gp-premium' );
_e( 'Item added to cart.', 'gp-premium' );
_n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'gp-premium' );
Thanks.
But how? My Site language is "German (Switzerland)".
In GeneratePress Child translations are no strings as you mentoined.
Cheers
I'm not sure how Loco Translate works. These translations are in the GP Premium plugin - not sure if that helps?
Hi Tom,
Hmm can't find these strings in GP Theme translation.
May I can download the PO and MO file that you can see the problem?
To reproduce only a blank site in German with GP and loco translate plugin is needed.
Otherwise maybe I can translate these strings directly in GP somewhere or via php filter?
Cheers.
Have you checked with their support?
The translation wouldn't be in the theme, it would be in the GP Premium plugin. Not sure if they separate things by theme/plugin?
Ah, I got it! Now it works. I reapply the site language and it works! :)
Thanks
Fun!
It works for 99%...
Now we have problems with the „item“ and „items“ string.
If the cart is emmpty and we add the first product to cart, the translations is right. If we now add a second item to the cart the string „items“ appears.
In loco translate I do not see a option to translate this string in GP premium translations file.
_n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'gp-premium' );
It may be something you need to bring up with them. _n is a core WordPress translation function where you can specific singular or plural.
Hello,
Okey. Thanks. I will check that with loco translate. :)
Or can I translate the stuff in another way? Offline or so?
Cheers
You can always sign up here: https://translate.generatepress.com/
Then you can submit the translations and we can approve them for the plugin :)