I´m trying to resolve one matter for 2 days without success.
I don´t know why but for some mysterious reasons, new translations in my plugin project did not work but it works perfectly for old translated labels.
My translation is visible inside .po and .mo
msgctxt "misc_postbox_label"
msgid "Visibility"
msgstr "Visibilité"
... connexion Abonnement État Visibilité...
In my php code :
_x( "Visibility", "misc_postbox_label", $this->current_plugin_domain ),
To debug this I tried to follow this.
Something could be the problem : I added this following code :
function debug_load_textdomain( $domain , $mofile ){
echo "Trying ",$domain," at ",$mofile,"<br />\n";
exit;
}
add_action('load_textdomain','debug_load_textdomain');
And the hook load_textdomain
is called but I got a blank page.
Someone knows why?
Someone has got an idea to resolve the entire problem ?
I´m trying to resolve one matter for 2 days without success.
I don´t know why but for some mysterious reasons, new translations in my plugin project did not work but it works perfectly for old translated labels.
My translation is visible inside .po and .mo
msgctxt "misc_postbox_label"
msgid "Visibility"
msgstr "Visibilité"
... connexion Abonnement État Visibilité...
In my php code :
_x( "Visibility", "misc_postbox_label", $this->current_plugin_domain ),
To debug this I tried to follow this.
Something could be the problem : I added this following code :
function debug_load_textdomain( $domain , $mofile ){
echo "Trying ",$domain," at ",$mofile,"<br />\n";
exit;
}
add_action('load_textdomain','debug_load_textdomain');
And the hook load_textdomain
is called but I got a blank page.
Someone knows why?
Someone has got an idea to resolve the entire problem ?
Share Improve this question edited Apr 26, 2019 at 12:57 J.BizMai asked Apr 25, 2019 at 16:41 J.BizMaiJ.BizMai 9002 gold badges10 silver badges30 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 2After a heavy investigation, I understood what is happening.
The solution to debug this was partially here but there were some php errors that´s why I got a blank page.
So, after to test :
- Which language is called thanks with
get_locale()
- Display
WP_LANG_DIR
to know where are language files are stored
I tried to know exactly which MO file was loaded for my plugin with this code ( code with no php/wordpress errors ):
function debug_load_textdomain( $domain , $mofile ){
echo "Trying " . $domain . " at " . $mofile . "<br />";
}
add_action('load_textdomain','debug_load_textdomain', 10, 2 );
I could see on my site this path for my plugin concerned:
my-plugin at /path-to-worpdress/wp-content/languages/plugins/my-plugin-fr_FR.mo
and... SURPRISE !!!!
This file does not contain my translation. Even if I uninstall my plugin and install again.
The reason is :
when you uninstall the plugin, the file
.../wp-content/languages/plugins/my-plugin-fr_FR.mo
is removed correctly but if you install your plugin again, the Wordpress core will search the.po
and.mo
files from the lastest stable version uploaded on wordpress and does not use your.po
and.mo
inside your current plugin folder in development.
.../wp-content/languages/plugins/my-plugin-fr_FR.po
# Translation of Plugins - My Plugin - Stable (latest release) in French (France)
# This file is distributed under the same license as the Plugins - My Plugin - Stable (latest release) package.
msgid ""
msgstr ""
"PO-Revision-Date: 2018-12-12 23:16:54+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: GlotPress/2.4.0-alpha\n"
"Language: fr\n"
"Project-Id-Version: Plugins - My Plugin - Stable (latest release)\n"
Conclusion
If your plugin was already uploaded on wordpress, and you want to test your new .po
and .mo
files, you have to delete /path-to-worpdress/wp-content/languages/plugins/my-plugin-fr_FR.mo
and Wordpress will automatically get the .mo
file inside your plugin folder.
.pot
file). But if I can, I'll look at that translation caching.. if you're sure it wasn't a server-side caching (e.g. Varnish).. try replicating the issue to be sure the translations were indeed being cached by WordPress, and do it on a site that's 101% cache-disabled... – Sally CJ Commented Apr 25, 2019 at 18:19