本地翻译:wp-admin菜单中未翻译的自定义发布和自定义分类标签

时间:2020-05-20 作者:toneyt

我目前正在用Loca translate翻译我的所有插件。这在前端和后端的所有元数据库中都可以正常工作,但在wp admin菜单中不行:

enter image description here

带红色圆圈的单词应该是德语,但不是。

My Custom Post Type:

<?php

function add_ons() {
    register_post_type(\'add_ons\',
        array(
            \'labels\'      => array(
                \'name\'          => __( \'Add-Ons\', \'add-ons\' ),
                \'singular_name\' => __( \'Add-On\', \'add-ons\' ),
            ),
            \'taxonomies\'  => array( \'add_ons_category\' ),
            \'public\'      => true,
            \'has_archive\' => true,
            \'show_ui\' => true,
            \'rewrite\' => array(
                \'slug\' => \'add-ons\'
            ),
            \'supports\' => array(
                \'title\',
                \'editor\',
                \'post-thumbnail\',
                \'custom-fields\',
                \'revisions\'
            )
        )
    );
}
add_action(\'init\', \'add_ons\');

function add_on_category() {
    register_taxonomy( \'add_ons_category\', \'add_ons\', array(
        \'label\'        => __( \'Add-On Category\', \'add-ons\' ),
        \'rewrite\'      => array( \'slug\' => \'add-on-category\' ),
        \'show_admin_column\' => true,
        \'hierarchical\' => true,
    ) );
}
add_action( \'init\', \'add_on_category\', 0 );
文本域是正确的,我已经在本地翻译字符串,他们只是没有显示在菜单中。但它们会显示在其他使用它们的地方。

有什么想法吗?

1 个回复
最合适的回答,由SO网友:toneyt 整理而成

对于任何有相同问题的人,我现在使用的是以下问题的公认答案中的解决方法:https://wordpress.stackexchange.com/a/30723/181214

我使用的解决方案超出了;编辑:另一个选项;这对鼻涕虫、名字、单数名字等都适用。

function get_labels() {
    // return a default slug
    if(!defined(\'WPLANG\') || !WPLANG || \'de_DE\' == WPLANG) return array(\'slug\' => \'produkt\', \'name\' => \'Produkte\', \'singular_name\' => \'Produkt\');

    $slugs = array(
        \'en_US\' => array(\'slug\' => \'product\', \'name\' => \'Products\', \'singular_name\' => \'Product\'),
        \'en_UK\' => array(\'slug\' => \'product\', \'name\' => \'Products\', \'singular_name\' => \'Product\'),
        \'de_DE\' => array(\'slug\' => \'produkt\', \'name\' => \'Produkte\', \'singular_name\' => \'Produkt\'),
        \'de_CH\' => array(\'slug\' => \'produkt\', \'name\' => \'Produkte\', \'singular_name\' => \'Produkt\'),
        \'fr_FR\' => array(\'slug\' => \'produit\', \'name\' => \'Produits\', \'singular_name\' => \'Produit\'),
        \'es_ES\' => array(\'slug\' => \'producto\', \'name\' => \'Productos\', \'singular_name\' => \'Producto\')
    );

    return $slugs[WPLANG];
}

function product() {
    $labels = get_labels();

    register_post_type(\'product\',
        array(
            \'labels\'      => array(
                \'name\'          => $labels[\'name\'],
                \'singular_name\' => $labels[\'singular_name\'],
            ),
            \'public\'      => true,
            \'has_archive\' => true,
            \'show_ui\' => true,
            \'rewrite\' => array(
                \'slug\' => $labels[\'slug\']
            ),
            \'show_in_menu\' => true,
            \'supports\' => array(
                \'title\',
                \'post-thumbnail\',
            )
        )
    );
}
add_action(\'init\', \'product\');