WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written a plugin that allows users to add information in the database. It runs well but I can't translate the information using WPML. This is a simple example of the problem:

$message = 'test'; // here I get the information of the DB
__($message, 'my-plugin');

Is there a way to workaround this problem? I don't know if we can use a variable instead of a string to translate. When I analize the widget in the Admin panel it don't show the string to translate.

This example works in WPML because is a string: __('test', 'my-plugin');

Thanks in advance.

share|improve this question
__()' and _e(); functions works with placeholders just fine and its a php functions and not a WPML functions, so either i'm not getting the question or it's just poorly stated, can you explain a bit more, what you are trying to do? – Bainternet Apr 4 '11 at 0:02
@Bainternet thanks for your answer, I'm trying to get information from the database and display with the translate functions __() and _e() , but instead of echoing a string like _e('message','myplugin'); I want to echo the information I get from the DB , so I have a variable with the content I get like `_e($message,'myplugin'). This works well, echoing the information, but when I go to the WPML to translate the string it doesn't appear and I can't translate it. – Albert Apr 4 '11 at 9:39
up vote 2 down vote accepted

If you want to have variables in your text to be translated the usual way would be with string formatting like so:

printf(__("text %s text2."), $message);

with integers:

printf(__("text %d text2."), $count);

with more then one placeholders:

printf(__("text %1$s text2 %2$S."), $message, $message2);

but the variable it self will not be translated in no way.

WPML doesn't run the code before __(); or _e(); function it only search the files for them, and that is why when you write something like this:

$message = 'test'; // here I get the information of the DB
__($message, 'my-plugin');

WPML only sees __($message, 'my-plugin'); where $message is empty.

share|improve this answer
Thank you very much, I thought this could happen so now I have to change my code using other ways to display the information, maybe using custom post types. – Albert Apr 4 '11 at 11:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.