Plugin translation not working apart from name and description

Question

I wrote a plugin that creates a custom post type and I tried to translate it using Poedit, but it’s not fully working. I did translate a few other plugins before and I’m not sure what’s causing this error:

The plugin’s name and description are correctly translated in the backend, but no post type names are translated.

Full Example

File Structure

test
├── languages
│   ├── test-de_DE.mo
│   ├── test-de_DE.po
│   └── test.pot
└── test.php

I defined the Text Domain test and Domain Path languages in the plugin header in test.php.

The post type is defined in the same file like so:

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');

I created a .pot file using the wp-cli command i18n make-pot .wp-contentpluginstest

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.0n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/testn"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>n"
"Language-Team: LANGUAGE <LL@li.org>n"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=UTF-8n"
"Content-Transfer-Encoding: 8bitn"
"POT-Creation-Date: 2020-06-12T15:08:36+02:00n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONEn"
"X-Generator: WP-CLI 2.4.0n"
"X-Domain: testn"

#. 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 ""

Then I used Poedit to create the german .po and .mo files.

With the plugin activated I can see the plugin’s name and description in german, but the added post type still shows up in english.

This is the .po file generated by 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.0n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/testn"
"Language-Team: n"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=UTF-8n"
"Content-Transfer-Encoding: 8bitn"
"POT-Creation-Date: 2020-06-12T15:08:36+02:00n"
"PO-Revision-Date: 2020-06-12 15:09+0200n"
"X-Generator: Poedit 2.3.1n"
"X-Domain: testn"
"Last-Translator: n"
"Plural-Forms: nplurals=2; plural=(n != 1);n"
"Language: de_DEn"

#. 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"

As a bonus, it also doesn’t translate (server side rendered) Gutenberg blocks that I created in the same plugin.

Any ideas how to fix the missing translations? Thanks!

0
, , Cebbi 8 months 0 Answers 92 views 0

Leave an answer