在PHP中,特別是在WordPress的,什麼是__('string')
和_x('string')
之間的區別?「雙下劃線」和「下劃線x」有什麼區別?
我閱讀WordPress的文檔和困惑。混亂的下很好的例子,從上Wordpress doc示例代碼繪製register_post_type()
:
$labels = array(
'name' => _x('Books', 'post type general name', 'your-plugin-textdomain'),
'singular_name' => _x('Book', 'post type singular name', 'your-plugin-textdomain'),
'menu_name' => _x('Books', 'admin menu', 'your-plugin-textdomain'),
'name_admin_bar' => _x('Book', 'add new on admin bar', 'your-plugin-textdomain'),
'add_new' => _x('Add New', 'book', 'your-plugin-textdomain'),
'add_new_item' => __('Add New Book', 'your-plugin-textdomain'),
'new_item' => __('New Book', 'your-plugin-textdomain'),
'edit_item' => __('Edit Book', 'your-plugin-textdomain'),
'view_item' => __('View Book', 'your-plugin-textdomain'),
'all_items' => __('All Books', 'your-plugin-textdomain'),
'search_items' => __('Search Books', 'your-plugin-textdomain'),
'parent_item_colon' => __('Parent Books:', 'your-plugin-textdomain'),
'not_found' => __('No books found.', 'your-plugin-textdomain'),
'not_found_in_trash' => __('No books found in Trash.', 'your-plugin-textdomain')
);
見['_x()'](https://codex.wordpress.org/Function_Reference/_x)和['__()'](HTTPS://codex.wordpress。 org/Function_Reference/_2)→上下文參數。 – mario