2

I create a plugin just for testing

/**
 * @package SurveyPlugin
 * @version 1.0
 */
/*
Plugin Name: Survey Plugin
Plugin URI: http:marcogomesweb.com
Description: This is survey
Author: NodeLondon
Version: 1.0
License: GPLv2 or later
Text Domain: survey-plugin
*/

function get_dummy_text() {
    $text = [
        __( 'city hotels' , 'survey-plugin' )
    ];
    return $text[0];
}

add_action('admin_notices', 'show_dummy_text');

function show_dummy_text(){
    $text = get_dummy_text();
    global $locale;
    echo "<br>". $locale . "<br>";
    echo "<p id='wp-admin-motivation'>$text</p>";
}


add_action( 'plugins_loaded', 'wan_loaded_textdomain');


function wan_loaded_textdomain(){

     $loadfiles = load_plugin_textdomain('survey-plugin', false, 
     dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

     plugin_basename( __FILE__ ). '/languages/' );



     var_dump($loadfiles); // is always false


}

I install Poedit I create a .mo file survey-plugi-es_ES.mo in /plugins/survey-plugin/languages/

enter image description here

survey-plugi-es_ES.mo

msgid ""
msgstr ""
"Project-Id-Version: Survey Plugin\n"
"POT-Creation-Date: 2019-03-15 14:16+0000\n"
"PO-Revision-Date: 2019-03-15 14:16+0000\n"
"Language-Team: Marcogomesr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: __\n"
"Last-Translator: \n"
"Language: es\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPath-1: survey-plugin.php\n"
"X-Poedit-SearchPathExcluded-0: src\n"
"X-Poedit-SearchPathExcluded-1: dist\n"

#: survey-plugin.php:79
msgid "city hotels"
msgstr "ciudad"

and this is what echo out

enter image description here

after changing the languages in the settings / site languages still showing the same,

I'm following this tutorial but still having no idea why

0

1 Answer 1

2

(Revised answer)

The simple answer is because WordPress could not find the MO file, despite the file itself exists (in the plugin's languages directory).

And here's why: The MO file needs to be named following this format: {text-domain}-{locale}.mo, and {text-domain}-{locale}.po for the PO file. See Loading Text Domain for further information.

So you're trying to load the MO file for the survey-plugin domain:

load_plugin_textdomain( 'survey-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' )

Hence for the es_ES locale (Español),

  • The MO file name has to be survey-plugin-es_ES.mo.

  • The PO file name has to be survey-plugin-es_ES.po.

And I think you may not be aware that the POT (translation template) file needs be named like so: {text-domain}.pot? E.g. survey-plugin.pot in your case.

Or was the survey-plugi just a typo? :)

But even if so, I hope this answer helps (other developers/readers).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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