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.

enter image description here

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 ""
  • 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 Nov 13 '18 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 Nov 14 '18 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 Nov 14 '18 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 Nov 14 '18 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 Nov 15 '18 at 11:03
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.