php - 如何更改自定义帖子的语言?
问题描述
我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/
推荐阅读
- excel - 使用 VBA 循环遍历子文件夹中的文件
- javascript - 如何制作一个像 UI 一样的表格来对其中的元素做出原生反应?
- javascript - 如何在课堂上进行全局解构?
- azure - 使用 Application Insights 监视 IIS 应用程序
- mongodb - 如何使用当前时间和文档中的另一个字段创建 mongodb 查询?
- java - 使用 eclipse 生成 .jar 文件后如何加载图像?
- sql-server - 从 SSMS 2008 迁移到 SSMS 2016 后,数据库服务器面临缓慢的问题
- html -
- 如何将导航栏中的最后一项设置在右侧
- kubernetes-ingress - 通过使用 Istio 端点身份验证,使用 Firebase 对 JWT 进行身份验证
- clips - CLIPS 无法识别 deftemplate 名称