I’m going through some legacy code and adding i18n functions throughout when I stumbled on a localisation snippet I found inside a pre_get_document_title
function: (simplified)
$title="Hello World";
__( $title, 'my_text_domain' );
This returns the correct, translated string. It was recently pointed out to me however, that this isn’t valid syntax as localisation functions should only receive a string; not a variable, nor a function return value. The recommended (and correct) syntax, as seen in numerous themes:
sprintf( __( '%s', 'my_text_domain' ), $title );
Having made this change, I find that all my titles are now still in English. i.e. nothing gets translated. All the language files are still there, all I did was modify the __() calls.
Is there something I missed?