translation - Translate strings not recognised in plugin

admin2025-06-03  2

I am trying to translate my plugin strings, but for some reason my plugin does not find the strings via the _e() and __() functions.

My plugin directory is called test-plugin.

My plugin /test-plugin/test-plugin.php files looks as follows:

<?php
/*
Plugin Name: Test plugin
Version: 1.0
Author: Robbert Vermeulen
License: GPL2
Text Domain: test-plugin
*/

_e( 'This is a test text', 'test-plugin' );
__( 'This is another test text', 'test-plugin' )


function test_plugin_load_plugin_textdomain() {
    load_plugin_textdomain( 'test-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'test_plugin_load_plugin_textdomain' );

?>

When I try to sync the strings the plugin only finds the values from my plugin description to translate.

What do I have to do so that the strings are recognized?

My test-plugin.pot file looks like:

#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Test plugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-13 16:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco /"

#. Author of the plugin
msgid "Robbert Vermeulen"
msgstr ""

#. Name of the plugin
msgid "Test plugin"
msgstr ""

I am trying to translate my plugin strings, but for some reason my plugin does not find the strings via the _e() and __() functions.

My plugin directory is called test-plugin.

My plugin /test-plugin/test-plugin.php files looks as follows:

<?php
/*
Plugin Name: Test plugin
Version: 1.0
Author: Robbert Vermeulen
License: GPL2
Text Domain: test-plugin
*/

_e( 'This is a test text', 'test-plugin' );
__( 'This is another test text', 'test-plugin' )


function test_plugin_load_plugin_textdomain() {
    load_plugin_textdomain( 'test-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'test_plugin_load_plugin_textdomain' );

?>

When I try to sync the strings the plugin only finds the values from my plugin description to translate.

What do I have to do so that the strings are recognized?

My test-plugin.pot file looks like:

#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Test plugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-13 16:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco https://localise.biz/"

#. Author of the plugin
msgid "Robbert Vermeulen"
msgstr ""

#. Name of the plugin
msgid "Test plugin"
msgstr ""
Share Improve this question edited Nov 14, 2018 at 5:30 Robbert asked Nov 13, 2018 at 17:12 RobbertRobbert 1,2756 gold badges23 silver badges47 bronze badges 8
  • Have you actually updated your plugin's POT file (languages/test-plugin.pot)? It should contain something like msgid "This is a test text". Or you haven't created that file..? – Sally CJ Commented Nov 13, 2018 at 19:22
  • @SallyCJ checkout my pot file in my question. The problem is that there are no strings other than the ones from the plugin description synced. – Robbert Commented Nov 14, 2018 at 5:32
  • You need to update your POT file so that it contains those new translatable strings. They're not automatically added to the file. – Sally CJ Commented Nov 14, 2018 at 5:59
  • 1 I just found how the plugin works. I need to update the template (.pot) file each time and then sync the language. – Robbert Commented Nov 14, 2018 at 8:13
  • 2 @SallyCJ Yes, but this plugin can extract the strings from the templates, but you need it needs an extra action only. So first sync the .pot file and then sync the language specific file. – Robbert Commented Nov 15, 2018 at 11:03
 |  Show 3 more comments

1 Answer 1

Reset to default 0

I just needed to update the template (.pot) file each time and then sync the language.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748966296a315224.html

最新回复(0)