Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 6 replies, has 2 voices.

Last updated by peterP-63 2 years, 6 months ago.

Assisted by: Bigul.

Author Posts
May 4, 2022 at 2:10 pm #11152089

peterP-63

Hello there!

Our Woocommerce Shop runs in German and English language. Is there a way to translate text given in snippets to another language?
e.g. code in the attached file

thanks,
Peter

11149973-wpml_3_3.jpg
May 4, 2022 at 2:22 pm #11152239

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hi Peter,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

Hope you have added this code to the functions.php of your theme. If so, please try the following steps after a full site backup and make sure the issue exists or not.

1) Visit WPML>>Theme and plugins localization page
2) Choose the theme from the *Strings in the theme* section
3) Click the *Scan the theme for strings* button to scan the theme strings
4) Wait until the process complete
5) Visit WPML>>Strings Translation, search for the strings, and translate
6) Visit the front end and confirm it is showing the translated strings for you.

Please refer to the following documentation for more details.

https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#scanning-for-hard-coded-strings

--
Thanks!

Bigul

May 6, 2022 at 8:02 am #11165405

peterP-63

Hi Bigul,

thanks for your suppor!
In my case the code is used in the Code Snippet plugin Version 2.14.3 and not in functions.php of the theme.

By following your advise I cannot find the Code Snippet plugin nor the text to be translated in WPML search options!?

May 6, 2022 at 10:18 am #11166303

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hi Peter,

Thank you for the updates. In this case, you can use WPML hooks(wpml_register_single_string & wpml_translate_single_string) for registering strings for translation and retrieving the translation.

Please check the following sample code and documentation links for more details.

$str = "Sorry, All sold out!";
do_action( 'wpml_register_single_string', 'WooCommerce', 'Sold Out', $str );
$str = apply_filters('wpml_translate_single_string', $str, 'WooCommerce', 'Sold Out' );

https://wpml.org/wpml-hook/wpml_register_single_string/

https://wpml.org/wpml-hook/wpml_translate_single_string/

--
Thanks!

Bigul

May 7, 2022 at 2:54 pm #11173221

peterP-63

Hi Bigul,

Thanks for your advises! I finally succeeded by installing "Woody Code Snippets 2.4.4" plugin which is claimed to be compatible with WPML.

Now the text from the code is translated and correctly shown on German site 🙂

However I realized that translation is not shown any more when I uncheck "string-tracking"!
I understand that this feature only should be used during development due to higher demand of resources!?

How can I manage that???

thank you,
Peter

string-tracking.jpg
May 8, 2022 at 12:20 pm #11175341

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hi Peter,

Thank you for the updates. When the Tracking strings option is enabled it will consume more memory, so not recommended on the live site.

Please note that the *Woody Code Snippets * plugin is not included on the WPML official compatibility list for the Plugins - https://wpml.org/plugin/. It does not mean that this plugin is not compatible with WPML, but our compatibility team has not tested it yet.

When we are using a snippet plugin it is storing the code in the Database, instead of files like plugins or themes. Therefore please use hooks(wpml_register_single_string & wpml_translate_single_string) for registering strings for translation and retrieving the translation. Refer to the following documentation for more details.

https://wpml.org/wpml-hook/wpml_register_single_string/

https://wpml.org/wpml-hook/wpml_translate_single_string/

--
Thanks!

Bigul