在网上搜索了几个小时后,我决定在这里问我的问题。我处于多站点环境中,我有以下自定义帖子类型代码:
$products_labels = array(
\'name\' => _x( \'Prodotti\', \'General post type name\', \'textdomain\' ),
\'singular_name\' => _x( \'Prodotto\', \'General post type name\', \'textdomain\' ),
\'menu_name\' => _x( \'Prodotti\', \'General post type menu label\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Genitore elemento:\', \'textdomain\' ),
\'all_items\' => __( \'Tutti gli elementi\', \'textdomain\' ),
\'view_item\' => __( \'Vedi\', \'textdomain\' ),
\'add_new_item\' => __( \'Aggiungi nuovo elemento\', \'textdomain\' ),
\'add_new\' => __( \'Aggiungi nuovo\', \'textdomain\' ),
\'edit_item\' => __( \'Modifica\', \'textdomain\' ),
\'update_item\' => __( \'Aggiorna\', \'textdomain\' ),
\'search_items\' => __( \'Cerca\', \'textdomain\' ),
\'not_found\' => __( \'Non trovato\', \'textdomain\' ),
\'not_found_in_trash\' => __( \'Non trovato nel cestino\', \'textdomain\' ),
);
$products_args = array(
\'label\' => __( \'Prodotti\', \'textdomain\' ),
\'description\' => __( \'Prodotti\', \'textdomain\' ),
\'labels\' => $products_labels,
\'supports\' => array( \'title\', \'thumbnail\', \'editor\', \'excerpt\', \'revisions\', \'page-attributes\' ),
\'taxonomies\' => array( \'product_category\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
);
我的一个网站是德语的,后台也用德语设置。所有字符串都已正确翻译(前端工作正常),de\\u de.mo文件加载良好,但从管理角度来看,标签未本地化,我无法理解为什么不本地化:(
这是加载文本域
load_theme_textdomain( \'textdomain\', THEMEPATH . \'/languages\' );
请查找所附图片
希望您能帮助我:(
更新时间:
我注意到所有字符串都写在函数中。php文件未翻译。翻译它们的唯一方法是在名为init action的新函数中插入字符串。
示例:
未翻译
$str = __(\'My string\',\'textdomain\');
已翻译:
function my_function_name()
{
$str = __(\'My string\',\'textdomain\');
echo $str;
}
add_action(\'init\',\'my_function_name\', 0);
更新2:
已解决。您必须加载load\\u theme\\u textdomain,而不是通过操作,而是直接写入文件函数的第一行。phpNow我的自定义帖子类型标签最终翻译为:)