I create a plugin just for testing
/**
* @package SurveyPlugin
* @version 1.0
*/
/*
Plugin Name: Survey Plugin
Plugin URI: http:marcogomesweb
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/
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
after changing the languages in the settings / site languages
still showing the same,
I'm following this tutorial but still having no idea why
I create a plugin just for testing
/**
* @package SurveyPlugin
* @version 1.0
*/
/*
Plugin Name: Survey Plugin
Plugin URI: http:marcogomesweb
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/
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
after changing the languages in the settings / site languages
still showing the same,
I'm following this tutorial but still having no idea why
Share Improve this question edited Mar 21, 2019 at 0:02 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Mar 15, 2019 at 14:27 MarcogomesrMarcogomesr 1313 bronze badges 01 Answer
Reset to default 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).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745670678a4639383.html
评论列表(0条)