I am adding a list of suggested plugins to my theme using TGM Plugin Activation – https://github.com/thomasgriffin/TGM-Plugin-Activation/
However, when I run theme check, about 40 or so recommendations popped up because the plugin uses variables in translatable functions. I was able to remove about half of the problems by typing in my text domain instead of using the variable used by the plugin author. However, I need help rectifying the error below:
RECOMMENDED: Possible variable $instance found in translation function
in class- tgm-plugin-activation.php. Translation function calls must
NOT contain PHP variables.
Here’s the code associated with the error:
$table_data[$i]['source'] = __( 'External Link', TGM_Plugin_Activation::$instance->domain );
I know that translation functions should look something like __(‘Item Name’, ‘text-domain’), but I am not sure what to do with the second part of the function:
TGM_Plugin_Activation::$instance->domain
How can I adjust this so that it will work properly with translations?
The translation strings not only get parsed during rendering (output on screen/in browser), but also by the GNU gettext parser. This one is not a PHP parser, so it can’t fetch variables. This is the only part of a Theme or a Plugin, where you need to repeat yourself and add the plain string to every translation/gettext function call.
Just to clarify this: Both above mentioned calls will work with POEdit. The first just won’t work, when Automattic/wp.org ever brings the automated translation tool that Mark Jaquith promised. And this is the part the “Theme Check”-Plugin nags about. You’re perfectly fine ignoring the “RECOMMENDED” messages. As you can read on this post by M.Jaquith – read briefly, then move to comments – this is just what gets recommended by “official” sources/lead developers.
Doesn’t look like the TGM code is properly translatable. You should simply change all the places in that code in which translation functions are being called to use your theme’s text domain.