Reputation: 1437
I have this code which I would like to localize for translation in the plugin I am building. Nothing on line seems to help. My own attempts return errors. Any help?
public function add_admin_pages() {
//add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' )
add_submenu_page(
'woocommerce',
_e( 'Exporter réservations', 'export-bookings-to-csv' ),
_e( 'Exporter réservations', 'export-bookings-to-csv' ),
'manage_options',
'export-bookings-to-csv',
array( $this,'export_bookings_to_csv')
);
}
Upvotes: 1
Views: 479
Reputation: 2200
The problem is that you are echoing the translation with _e()
You need to use __()
to return the string.
public function add_admin_pages() {
//add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' )
add_submenu_page(
'woocommerce',
__( 'Exporter réservations', 'export-bookings-to-csv' ),
__( 'Exporter réservations', 'export-bookings-to-csv' ),
'manage_options',
'export-bookings-to-csv',
array( $this,'export_bookings_to_csv')
);
}
You will find details when to use __() or _e() here
$hello = __('Hello', 'txt-domain');
echo __('Hello', 'txt-domain');
echo $hello;
or using _e()
_e('Hello', 'txt-domain');
Upvotes: 4