[英]How to change the language of the custom post?
我在我的項目中使用了多語言的polylang
插件。 我使用以下代碼創建了一個自定義事件。
function post_types()
{
$labels = array(
"name" => "Events",
"add_new_items" => "Add New Event",
"edit_item" => "Edit Event",
"all_items" => "All Events",
"singular_name" => "Event"
);
$events = array(
"has_archive" => true,
"public" => true,
"menu_icon" => "dashicons-calendar",
"labels" => $labels,
);
register_post_type("event", $events);
}
add_action("init", "post_types");
我不確定如何更改此活動中帖子的語言?
請使用文本域:
function post_types()
{
$labels = array(
"name" => __( "Events", "your-text-domain" ),
"add_new_items" => __( "Add New Event", "your-text-domain" ),
"edit_item" => __( "Edit Event", "your-text-domain" ),
"all_items" => __( "All Events", "your-text-domain" ),
"singular_name" => __( "Event, "your-text-domain" )"
);
$events = array(
"has_archive" => true,
"public" => true,
"menu_icon" => "dashicons-calendar",
"labels" => $labels,
);
register_post_type("event", $events);
}
add_action("init", "post_types");
然后為您想要的語言創建一個語言文件(.po/.mo)。 我基本上使用 Loco Translate Plugin 來創建語言文件。
了解更多: https : //developer.wordpress.org/apis/handbook/internationalization/localization/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.