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.
echo sprintf(__("text %s", 'your__text_domain'), $data);
I'm surprised no one mentioned the "translators" comment, that tells the translator what each variable in the sprintf
is. Examples:
sprintf(
/* translators: %s: Name of a city */
__( 'Your city is %s.', 'my-plugin' ),
$city
);
sprintf(
/* translators: 1: Name of a city 2: ZIP code */
__( 'Your city is %1$s, and your zip code is %2$s.', 'my-plugin' ),
$city,
$zipcode
);
See: https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#variables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With