If you want to have variables in your text to be translated the usual way would be with string formatting like so:
<?php
printf(__("text %s text2."), $message);
?>
with integers:
<?php
printf(__("text %d text2."), $count);
?>
with more then one placeholders:
<?php
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.