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

Last updated by alexanderA 1 year ago.

Assigned support staff: Riffaz.

Author Posts
October 7, 2018 at 11:26 am #2793796

alexanderA

Hello. I have used WPML to translate my site into French and Chinese. At the bottom of one of my English pages (hidden link) is a few paragraphs of text. I would like to ensure the text is translated on the French and Chinese pages. What is the best way to do this?

The text in-question has been added to the page via code in the PHP template in-question (see attached screenshot--full pastebin of code here: https://pastebin.com/6a4iri7Q). Would it be best to wrap the code in a _() function, then translate it via WPML-->String Translation? Or should I not use WPML for this, and simply add the translations to the PHP template (and ensure they are displayed when the proper page loads)?

Thanks.

October 8, 2018 at 10:48 am #2795659

Riffaz
Supporter

Languages: English (English )

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

Hi Alexander,

To add translatable strings, you can use the WordPress functions like __() or _e(). Eg:

<?php echo __( 'Your String', 'your-context'); ?>

or:

<?php _e( 'Your String', 'your-context'); ?>

Then, click on WPML > Theme and Plugins Translations. Look for 'Strings in the theme' and click on the 'Scan the theme for strings' button.

Again in WPML > String Translation, you can translate the strings.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

You only need to replace "Your String". The "Your-Context" is the context of your theme. For you find your context, it is usually the functions.php file. For example:

load_theme_textdomain( 'twentyfourteen', get_template_directory() . '/languages' );

In this example, the default theme of WordPress, the context is 'twentyfourteen'.

In the example, your string should be:

<?php _e( 'Your String', 'twentyfourteen'); ?>

This should be repeated for all strings.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Riffaz.

October 8, 2018 at 11:44 am #2795841

alexanderA

OK thanks for that. We can consider this resolved.