WordPress不支持自定义帖子类型的_x()标签函数的翻译

问题描述 投票:0回答:1

在我正在开发的WordPress主题中,我注册了一个名为'Project'的自定义帖子类型,如下。

function add_custom_post_type() {

register_post_type( 'project', 
    array(
        'label'         => __( 'Projects', 'maria' ),
        'labels'        => array(
            'name'               => _x( 'Projects', 'post type general name', 'maria' ),
            'singular_name'      => _x( 'Project', 'post type singular name', 'maria' ),
            'menu_name'          => _x( 'Projects', 'admin menu', 'maria' ),
            'name_admin_bar'     => _x( 'Project', 'add new on admin bar', 'maria' ),
            'add_new'            => _x( 'Add New', 'project', 'maria' ),
            'add_new_item'       => __( 'Add New Project', 'maria' ),
            'new_item'           => __( 'New Project', 'maria' ),
            'edit_item'          => __( 'Edit Project', 'maria' ),
            'view_item'          => __( 'View Project', 'maria' ),
            'all_items'          => __( 'All Projects', 'maria' ),
            'search_items'       => __( 'Search Projects', 'maria' ),
            'parent_item_colon'  => __( 'Parent Projects:', 'maria' ),
            'not_found'          => __( 'No Projects found.', 'maria' ),
            'not_found_in_trash' => __( 'No Projects found in Trash.', 'maria' )
            ),
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail' ),
        'rewrite'       => array( 'slug' => __( 'project' ))
        )
    );
}
add_action( 'init', 'add_custom_post_type' );

[使用应用程序Poedit,我现在尝试将自定义帖子类型的标签翻译成德语。我正在导入功能/关键字___e_x。字符串按预期显示。

[https://abload.de/img/screenshot2019-09-29av4jhv.png(屏幕截图)

但是,在翻译我的.po文件并编译.mo文件以进行WordPress本地化时,WordPress似乎只接受我为___e函数输入的翻译,而忽略了_x函数。

[https://abload.de/img/screenshot2019-09-29ah7jxx.png(屏幕截图)

在我的仪表板中,尽管ProjectsAdd New按钮已分别翻译为ProjekteErstellen,但仍以英文显示。

我在做什么错?非常感谢。

wordpress custom-post-type gettext poedit
1个回答
0
投票

[好,虽然我无法解决WordPress无法兑现_x函数的翻译的问题,但通过使用以下解决方法,我可以正确显示标签。

在我的register_post_type函数中,我将所有_x函数更改为__函数(在过程中删除了上下文参数)。最终的工作代码如下:

function add_custom_post_type() {

register_post_type( 'project', 
    array(
        'label'         => __( 'Projects', 'maria' ),
        'labels'        => array(
            'name'               => __( 'Projects', 'maria' ),
            'singular_name'      => __( 'Project', 'maria' ),
            'menu_name'          => __( 'Projects', 'maria' ),
            'name_admin_bar'     => __( 'Project', 'maria' ),
            'add_new'            => __( 'Add New', 'maria' ),
            'add_new_item'       => __( 'Add New Project', 'maria' ),
            'new_item'           => __( 'New Project', 'maria' ),
            'edit_item'          => __( 'Edit Project', 'maria' ),
            'view_item'          => __( 'View Project', 'maria' ),
            'all_items'          => __( 'All Projects', 'maria' ),
            'search_items'       => __( 'Search Projects', 'maria' ),
            'parent_item_colon'  => __( 'Parent Projects:', 'maria' ),
            'not_found'          => __( 'No Projects found.', 'maria' ),
            'not_found_in_trash' => __( 'No Projects found in Trash.', 'maria' )
            ),
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail' ),
        'rewrite'       => array( 'slug' => __( 'project' ))
        )
    );
}
add_action( 'init', 'add_custom_post_type' );
© www.soinside.com 2019 - 2024. All rights reserved.