Why strings don't appear in "String translation" of WPML?

iWizard picture iWizard · Nov 10, 2013 · Viewed 13.3k times · Source

I have in my php files string like this:

<?php
__('My string A', 'a_theme');
_e('My string B', 'a_theme');
?>

and there are not appearing in "String translation" .

I have also bought and installed this theme: http://preview.ait-themes.com/index.php?bartype=desktop&theme=touroperator and strings from that theme aren't also appearing in "Strings translation" of WPML.

This is one example of string which was already in theme when I installed it:

<input type="text" id="dir-searchinput-location" class="dir-searchinput-select" placeholder="{__ 'Destination'}">

Is there some extra configuration which I need to do or something else?

Thanks for help

Answer

user2895499 picture user2895499 · Nov 10, 2013

To get strings to appear in String Translation, you first need to go to Theme and plugins localization. Scroll down to the Strings in the theme section and then click the Scan the theme for strings button. WPML will then detect any unregistered or newly added strings that are properly formatted for localization.

If it works, you'll see your theme a-theme listed in the Domain column and the number of detected strings in the Count column. Clicking the View strings that need translation button will take you to String Translation. If any of the strings aren't properly formatted for localization, the count won't be updated.

If you update existing strings or add new ones, you'll need to rescan before WPML adds them to String Translation.

The formatting in your first example looks OK and WPML should detect the strings, but in the second example, you haven't declared a domain. Without a domain, WPML won't pick up the string.

The correct format is

__('Your string', 'yourDomain') or _e('Your string', 'yourDomain')

In this case, the domain should be the name of your theme, 'a_theme'.