Why custom plugin text not displaying in string translations under WPML translation option

Before we further discuss any solution regarding this issue, I first of all give you an advice to upgrade below WPML plugins to it’s latest version for all updated functionality.
WPML Multilingual CMS
WPML String translation
WPML Translation Management
WPML Media Translation
Here are some troubleshooting guide to successfully translate a custom plugin text and make it compatible with WPML.

If you have custom plugin which have hard-coded strings written in function then you can scan for hard-coded strings from below option available in WPML plugin setting page below

  1. WPML → Theme and Plugins Localization
  2. Select the plugin name checkbox and click to scan

After the scan process done, you can able to see the strings on the String Translation option WPML

But if you have already tried with above option already then you definitely need to change in your plugin code translatable and added to String Translation to make it WPML compatible because all string will only appear in WPML string translation option if it’s WPML compatible otherwise WPML will not able to find any custom plugin or theme content automatically.

If you displaying any string in frontend, you have to wrap each string within a __() function & you also have to add a domain name to which the string belongs to. Also, if you will use same domain name for your plugin strings then it will be easy to find in staring translation option in WPML

It is very important to apply same domain name for entire plugin code because it is standard practice we must follow as WordPress plugin developer.

First of all, custom plugin must be register plugin text domain like below method.

load_plugin_textdomain( 'MY_TEXT_DOMAIN', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

Now there are different method in PHP programming to print any string so we can use any method as per our requirement

below is the different example of each method:

__( 'Hello World', 'MY_TEXT_DOMAIN' );

here, we have a string, “'Hello World'”, that belongs to 'MY_TEXT_DOMAIN' domain:

_e( 'Hello World', 'MY_TEXT_DOMAIN' );

If you need to echo a string to the browser, you should use the _e() function.

<a href="www.codesanitize.com" ><?php esc_html_e( 'Hello World', 'MY_TEXT_DOMAIN'); ?></a>

If you have a link that is separated from the text in <?php ?> then you should follow above syntax

Now, after change plugin code completely as per above guide, you should follow normal scan option for newly added domain name

So we will use below available option in WPML plugin setting page

  • Go to WPML → Theme and Plugins Localization
  • Select the plugin name checkbox and click to scan
  • Go to WPML -> string translation
  • Check dropdown for domain name and filter with your new domain name
  • Now all string will appear in result
  • Translate all string on language accordingly and click on translation in complete checkbox
  • If you cache plugin installed then clear the cache and check frontend for updated content
  • That’s it! all done

Hope, this above solution will work for you. All the best.
Next Post »