我正在构建一个wordpress插件,它将注册一个帖子类型。我正在尝试设置一个简单的测试用例,它所做的只是用get text函数注册一个post类型,然后用poedit翻译它。我已成功创建。采购订单和。mo文件,并使用以下代码加载它们:
add_action(\'init\', \'client_functions_textdomain\');
function client_functions_textdomain(){
load_plugin_textdomain( \'client-functions\', false, dirname( plugin_basename( __FILE__ ) ) . \'/languages/\' );
}
如果我在加载这个之后立即测试gettextcall,那么一切都可以正常转换。load\\u plugin\\u textdomain()返回true。
但是,当我后来尝试用以下代码(取自codex)注册帖子类型时,它不会翻译:
add_action( \'init\', \'codex_book_init\' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array(
\'name\' => _x( \'Books\', \'post type general name\', \'client-functions\' ),
\'singular_name\' => _x( \'Book\', \'post type singular name\', \'client-functions\' ),
\'menu_name\' => _x( \'Books\', \'admin menu\', \'client-functions\' ),
\'name_admin_bar\' => _x( \'Book\', \'add new on admin bar\', \'client-functions\' ),
\'add_new\' => _x( \'Add New\', \'book\', \'client-functions\' ),
\'add_new_item\' => __( \'Add New Book\', \'client-functions\' ),
\'new_item\' => __( \'New Book\', \'client-functions\' ),
\'edit_item\' => __( \'Edit Book\', \'client-functions\' ),
\'view_item\' => __( \'View Book\', \'client-functions\' ),
\'all_items\' => __( \'All Books\', \'client-functions\' ),
\'search_items\' => __( \'Search Books\', \'client-functions\' ),
\'parent_item_colon\' => __( \'Parent Books:\', \'client-functions\' ),
\'not_found\' => __( \'No books found.\', \'client-functions\' ),
\'not_found_in_trash\' => __( \'No books found in Trash.\', \'client-functions\' )
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => _x( \'book\', \'URL slug\', \'client-functions\' ) ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'book\', $args );
}
我怀疑这与两者都被挂接到“init”操作中,并且在加载文本域之前进行注册有关?我尝试了以下方法,但没有成功:
- 将优先级0添加到TextDoAdmin操作中,将优先级20添加到book_init函数中
- 我已将文本域加载到“plugins_loaded”操作中
任何帮助都将不胜感激!
谢谢Malthe