$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>translation - Translate strings not recognised in plugin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

translation - Translate strings not recognised in plugin

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far