8

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

iWizard
  • 6,816
  • 19
  • 67
  • 103

3 Answers3

24

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'.

user2895499
  • 508
  • 4
  • 8
  • 1
    You are right about all except two things. In second example WPML won't detect string because it is smarty tpl and wpml does not detect strings in tpls. About domain, if you set only like that __('My string'), this will work (tested). – iWizard Nov 11 '13 at 08:30
  • "If it works...". What about when it doesn't work? :) The scanner can't find any of my strings. Neither in my theme or my plugins. – gubbfett Mar 09 '16 at 15:33
  • @gubbfett are you using string literals for the domain? I tried to use a constant a while back and WPML wouldn't find it. The parser was built to require a string literal. – Matt Vanderpol Apr 28 '16 at 00:41
2

I have same problem, my theme is "bookyourtravel", and plugin "WPML string translation",did not translate these texts:

<?php _e('Accommodations', 'bookyourtravel'); ?>
<?php _e('Tour', 'bookyourtravel'); ?>
<?php _e('Accommodation', 'bookyourtravel'); ?>    

No translated!!!

My solution was:

  1. In WPML go to "localization of themes and plugins", check in Translated by WPML, then clic en Save.
  2. Now in, "Translated string", clic in button: save the settings and rescan strings.

If you use Cache, then Clear all cache in pages.

ready, this worked!!!!!!!

source : https://wpml.org/forums/topic/using-gettext-for-hard-coded-strings-what-else/

ederrafo
  • 31
  • 1
1

Those strings are cached somehow. So, if you added new one (the right way) and it still doesn't appear in String translation go to "Theme and plugin localization" and hit "Scan the theme for strings" button. This will re-index strings and your newly added one should appear (worked for me).

MilanG
  • 6,994
  • 2
  • 35
  • 64