简体   繁体   中英

How to localize the title in add_menu_page in WordPress

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') 
        );
    }

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');   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM