I am creating an online shop using wordpress and woocommerce and came across the following question:
How can I translate the text in the WooCommerce Cart Sidebar Widget?
I was able to translate some of the text by writing the following code into my functions.php in my child theme:
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Text to translate', 'Translation', $translated);
return $translated;
}
Some of the text gets translated using the code above, while other strings are not affected by it. I've noticed that mostly strings within a <span>
tag are not translated, although there is one within a <a>
tag aswell.
How can I translate the remaining text?
Thanks