在注册帖子类型之前加载插件文本域

时间:2014-07-03 作者:Malibur

我正在构建一个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

1 个回复
SO网友:Malibur

事实证明,您必须在pot文件的配置中添加一些特殊的函数嗅探(从http://www.cssigniter.com/ignite/wordpress-poedit-translation-secrets/):

__
_e
__ngettext:1,2
_n:1,2
__ngettext_noop:1,2
_n_noop:1,2
_c
_nc:4c,1,2
_x:1,2c
_nx:4c,1,2
_nx_noop:4c,1,2
_ex:1,2c
esc_attr__
esc_attr_e
esc_attr_x:1,2c
esc_html__
esc_html_e
esc_html_x:1,2c

结束

相关推荐

wp_list_tables bulk actions

如何在扩展的WP\\U List\\U表中触发批量操作。我一直在将以下批量操作添加到may table的选择框中,但在Apply上不会发生任何事情下面是我如何添加批量操作的function get_bulk_actions() { $actions = array( \'delete\' => \'Delete\', \'parsing\' => \'Parsen\' );