我写了一个插件,创建了一个自定义的帖子类型,我试图用Poedit翻译它,但它并没有完全起作用。我之前翻译过一些其他插件,我不确定是什么导致了这个错误:
插件的名称和描述在后端被正确翻译,但没有帖子类型名称被翻译。
完整示例
File Structure
test
├── languages
│ ├── test-de_DE.mo
│ ├── test-de_DE.po
│ └── test.pot
└── test.php
我定义了文本域
test
和域路径
\\languages
在插件标题中
test.php
.
post类型在同一文件中定义如下:
test.php
<?php
/**
* Plugin Name: A Test
* Description: A Test Plugin
* Version: 1.0.0
* Text Domain: test
* Domain Path: /languages
*/
function test_custom_post_types()
{
register_post_type(\'test_post\', [
\'labels\' => [
\'name\' => __(\'Test Posts\', \'test\'),
\'menu_name\' => __(\'Test Posts\', \'test\'),
],
\'public\' => true,
]);
}
add_action(\'init\', \'test_custom_post_types\');
我创建了一个
.pot
文件使用
wp-cli
命令
i18n make-pot .\\wp-content\\plugins\\test\\
languages/test.pot
# Copyright (C) 2020
# This file is distributed under the same license as the A Test plugin.
msgid ""
msgstr ""
"Project-Id-Version: A Test 1.0.0\\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/test\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <[email protected]>\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"POT-Creation-Date: 2020-06-12T15:08:36+02:00\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"X-Generator: WP-CLI 2.4.0\\n"
"X-Domain: test\\n"
#. Plugin Name of the plugin
msgid "A Test"
msgstr ""
#. Description of the plugin
msgid "A Test Plugin"
msgstr ""
#: test.php:15
#: test.php:16
msgid "Test Posts"
msgstr ""
然后我用Poedit创建了德语
.po
和
.mo
文件。
激活插件后,我可以用德语看到插件的名称和描述,但添加的帖子类型仍然用英语显示。
这是。Poedit生成的po文件:
languages/test-de_DE.po
# Copyright (C) 2020
# This file is distributed under the same license as the A Test plugin.
msgid ""
msgstr ""
"Project-Id-Version: A Test 1.0.0\\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/test\\n"
"Language-Team: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"POT-Creation-Date: 2020-06-12T15:08:36+02:00\\n"
"PO-Revision-Date: 2020-06-12 15:09+0200\\n"
"X-Generator: Poedit 2.3.1\\n"
"X-Domain: test\\n"
"Last-Translator: \\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\\n"
"Language: de_DE\\n"
#. Plugin Name of the plugin
msgid "A Test"
msgstr "Ein Test"
#. Description of the plugin
msgid "A Test Plugin"
msgstr "Ein Test-Plugin"
#: test.php:15 test.php:16
msgid "Test Posts"
msgstr "Test Beiträge"
另外,它也不会翻译我在同一个插件中创建的古腾堡块(服务器端渲染)。
有没有办法修复缺失的翻译?谢谢