Translating WP with __() and sprintf()

D. A. picture D. A. · Apr 30, 2016 · Viewed 10.3k times · Source

I'm trying to translate WP theme. I have this code:

$translation = __( get_color(), 'textdomain' );

It works, I get color dynamically from get_color() function, and it translates well. But when I use "Theme Check" plugin I get error for this code.

I need to use this instead:

$translation = sprintf( __( '%s', 'textdomain' ), get_color() );

But in that case my placeholder %s doesn't translates, and I get original color name (not translated).

What I'm doing wrong? Thank you.

Answer

Mahdi Bashirpour picture Mahdi Bashirpour · Feb 10, 2018
echo sprintf(__("text %s", 'your__text_domain'), $data);