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.
If you want to have variables in your text to be translated the usual way would be with string formatting like so:
with integers:
with more then one placeholders:
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:WPML only sees
__($message, 'my-plugin');
where $message is empty.