1

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?

2 Answers 2

3

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.

// Wrong:
__( 'External Link', TGM_Plugin_Activation::$instance->domain );

// Right:
__( 'External Link', 'your_textdomain' );

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.

0
-1

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.

3
  • In fact it is fully translatable, but not by the automated system that the wp.org repository ... imagines.
    – kaiser
    Commented Jan 15, 2013 at 19:10
  • hmm, might have misunderstood something in that code. Commented Jan 15, 2013 at 20:35
  • It just doesn't come very clear in the question, that it's actually about the Theme Checker plugin complaining about the variable in it.
    – kaiser
    Commented Jan 15, 2013 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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