I'm creating a widget but the title and description is not translatable.
I'm often face this problem with arrays, I use esc_html__()
inside the array which is supposed to return the translated string to the $key
but for some reason it doesn't work, so I find myself using the esc_html__()
outside the array, however how can I do that here:
function __construct() {
$op = array(
'name' => esc_html__( 'some title', 'my-plugin' ),
'description' => esc_html__( 'some description goes here', 'my-plugin' )
);
parent::__construct( 'pk_members_widget', '', $op );
}
Most importantly, why it doesn't work when you add it in the array? Thanks.
esc_html_e()
and_e()
wouldn't work but there's no reason what you've got there shouldn't work. At least in terms of those functions. You've got the name in the wrong place though. The widgets name goes in the 2nd argument of the constructor, not the options array.