0

I am using the following piece of code that is failing a WordPreess theme check:

        'label'     => __( $value, '__gwfc__' ),

When I do a WP theme check I get the following:

Translation function calls must NOT contain PHP variables.

Could anyone please tell me the correct code for this?

2 Answers 2

1

Its not possible to translate variables. Why: Wordpress isnt using a system like google-translator. Wordpress got a fixed file where the translations are stored. So there is a fixed amout of elements which can be translated, nothing more.

If $value is picked out of, for example, a form-option you could swap throught like this:

switch ($value) {
    case 'example':  'label' => __( 'example', '__gwfc__' );
    case 'example2': 'label' => __( 'example2', '__gwfc__' );
    case 'example3': 'label' => __( 'example3', '__gwfc__' );
    case 'example4': 'label' => __( 'example', '__gwfc__' );
}

Just be sure the string which should be translated is configured in your translation-file!

Good luck.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to replace $value with the actual hard coded string it represents. The reason for this is that the internationalization parser has no real way to interpret PHP variables when it is running the translation, so it won't know what $value means.

It doesn't feel right, but to get around this message you'll want to plug in the hard coded value of $value.

So find the value of $label, and for example if it is 'foo', then just change the code to:

'label'     => __( 'foo', '__gwfc__' ),

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.