How to use esc_attr__ with custom translation function?

As your function returns the translated string, you could pass the translation function as parameter for esc_attr() and esc_attr_e():

esc_attr__( __myfunction( 'no_comments' ) );
esc_attr_e( __myfunction( 'no_comments' ) );

But esc_attr__() and esc_attr_e() will perform translation tasks that you don’t need because you handle the translation at your own, so I think it is better to use esc_attr() only:

esc_attr( __myfunction( 'no_comments' ) );

and

echo esc_attr( __myfunction( 'no_comments' ) );

tech