I checked the page and can see that it is now translated.
Another question regarding this:
We have a custom plugin on the site which shows a popup message with a heading text and button options "Yes" and "No".
How can we make the heading text translatable in other languages? If we use the same process you mentioned, what would we have to do in that case?
We have used esc_html__() inside the h2 tag in our custom code.
You won't follow the same workflow here because it's not a text that you can change on an option page.
'esc_html__()' is the correct function to retrieve translation, please make sure that you add the domain name as a second argument.
1. Your code should look like this:
echo esc_html__( 'Text to transalate', 'text-domain-here' );
2. Scan your plugin
- Go to "WPML > Theme and plugins localization"
- Select your plugin and click on "Scan selected plugins for strings"
- Wait until the operation is completed
3. Translate
- Go to "WPML > String Translation" to translate them
The tutorial I've shared explains different methods. This one is "Scanning the Theme or Plugin"
We got the text using this method.
Although there is another text we are passing through using AJAX. This string is sent back to the JS request to display on the page after the content is loaded.
Once you add the dependency, you can use the i18n functions in your JavaScript file. Here’s an example of how to use the __() function to translate a string:
const { __ } = wp.i18n;
alert( __( 'This is a translatable sentence', 'your-text-domain' ) );