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 1 reply, has 2 voices.

Last updated by Rohan Sadanandan 2 weeks, 5 days ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
October 2, 2019 at 5:37 pm

christopherM-17

I am trying to:

Translate this string " results found in " from my searchform.

This is the compiled html result:

<span class="search-results-count">25 results found in .0123 seconds</span>

This is the code behind it:

<span class="search-results-count"><?php global $wp_query;
echo $wp_query->found_posts.' results found in ';
timer_stop(1); ?> seconds</span>

No results.

SELECTED - Translate themes and plugins using WPML's String Translation only (don't load .mo files) and
Use theme or plugin text domains when gettext calls do not use a string literal

See hidden link

Thank you

October 2, 2019 at 9:43 pm #4683357

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for contacting WPML Support.

Please make sure that you are following WordPress internalization standards while writing code for themes/plugins. Then only WPML can pick the strings for translation. You can read more about this here: https://codex.wordpress.org/I18n_for_WordPress_Developers

I've just modified your code:

<span class="search-results-count">
<?php 
	global $wp_query;
	echo $wp_query->found_posts;
	_e(' results found in ','theme-text-domain');
	timer_stop(1); 
	_e(' seconds','theme-text-domain');
?>
</span>

As you can see, the texts must be wrapped in GetText calls & there must be a textdomain argument.

After placing this code in the template file, you need to follow the below steps:
- Navigate to WPML > Theme and plugins localization > Strings in the themes > Select your theme & click on "Scan selected theme for strings"
- Once it is completed, navigate to WPML > String Translation & search for the string.

You can also read these documentations for more details regarding string translation:
https://wpml.org/documentation/getting-started-guide/string-translation/
https://wpml.org/faq/language-setup/

Thanks,
Rohan