niestandardowe typy postów – Tłumaczenie wtyczek nie działa poza nazwą i opisem
Napisałem wtyczkę, która tworzy niestandardowy typ postu i próbowałem go przetłumaczyć za pomocą Poedit, ale tak nie jest w pełni pracujący. Przetłumaczyłem już kilka innych wtyczek i nie jestem pewien, co jest przyczyną tego błędu:
Nazwa i opis wtyczki są poprawnie przetłumaczone w backendie, ale nazwy typów postów nie są tłumaczone.
File Structure
test
├── languages
│ ├── test-de_DE.mo
│ ├── test-de_DE.po
│ └── test.pot
└── test.php
Zdefiniowałem domenę tekstową test
i ścieżka domeny \languages
w nagłówku wtyczki w test.php
.
Typ postu jest zdefiniowany w tym samym pliku w następujący sposób:
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');
Stworzyłem .pot
plik za pomocą wp-cli
Komenda 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:
"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 ""
Następnie użyłem Poedit do stworzenia języka niemieckiego .po
I .mo
akta.
Po aktywowaniu wtyczki widzę nazwę i opis wtyczki w języku niemieckim, ale typ dodanego postu nadal pojawia się w języku angielskim.
To jest plik .po wygenerowany przez Poedit:
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:
"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"
Jako bonus, nie tłumaczy również (renderowanych po stronie serwera) bloków Gutenberga, które utworzyłem w tej samej wtyczce.
Jakieś pomysły, jak naprawić brakujące tłumaczenia? Dzięki!