This thread is resolved. Here is a description of the problem and solution.
Problem:
The client needs to make the heading text in a custom plugin translatable, as well as another text passed through using AJAX.
Solution:
For the heading text:
1. Ensure you use the
esc_html__()
function with the text domain specified, like this:
echo esc_html__( 'Text to translate', 'text-domain-here' );
2. Scan your plugin for strings:
- Navigate to WPML > Theme and plugins localization
- Select your plugin and click on Scan selected plugins for strings
- Wait for the operation to complete
3. Translate the strings:
- Go to WPML > String Translation and translate them.
For AJAX-passed text:
1. Declare 'wp-i18n' as a dependency in your JS file:
wp_register_script( 'sample-script', plugins_url( 'app.js', __FILE__ ), array( 'wp-i18n' ) );
2. Use the i18n functions to translate strings in your JavaScript:
const { __ } = wp.i18n; alert( __( 'This is a translatable sentence', 'your-text-domain' ) );
For further guidance, refer to the tutorial on scanning themes or plugins and the section on Adding GetText Calls to JavaScript (JS) Code in our documentation.
If this solution does not apply to your case, or if it seems outdated, please check the related known issues, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. We highly recommend opening a new support ticket if needed.
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 is split from https://wpml.org/forums/topic/split-translated-page-content-is-reset-to-default-language/
This topic contains 3 replies, has 0 voices.
Last updated by 1 month, 1 week ago.
Assisted by: Nicolas V..