__() with sprintf returns untranslated string

The order of the functions being called is wrong.

With this code:

sprintf( __( '%s', 'my_text_domain' ), $title );
  • You are trying to translate the string ‘%s’ in the domain ‘my_text_domain’.
  • you are then replacing the translated string for ‘%s’ (which is ‘%s’), by the content of the variable $title.
  • Therefore your code is similar to sprintf( '%s', $title);

What you should do:

__( sprintf( '%s', $title ), 'my_text_domain' );
  • sprintf() will return your title
  • __() will translate the returned title

By the way, if you plan to use the title of the post only, you probably don’t need to use sprintf() but instead:

__( $title, 'my_text_domain );

tech