2

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 ?

  • So this may sound silly, but have you actually uploaded the updated MO and PO files to your site?.. Could it be because of caching? How did you create/regenerate the files? Do you use Loco Translate? – Sally CJ Apr 25 '19 at 17:26
  • Yes, I checked about the MO and PO on the server. It seems to have no cache because it is on a developement environment without cache plugins. I use Poedit to do translations. When I removed the MO and Po on the server, translated labels are still translated, so weird... – J.BizMai Apr 25 '19 at 17:30
  • I reset the wordpress and I add my plugin again and that works. It seems to be a cache system but I would like to know more anout what Wordpress does exaclty with po and mo files because it seems to have a cache system. – J.BizMai Apr 25 '19 at 17:56
  • I haven't checked that, probably because I have never run into such an issue and that I normally use the Loco Translate plugin when creating/editing the translations (from a POT/.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 Apr 25 '19 at 18:19
  • I did some tests without understanding. Do you think it could be a link with Project-Id-Version will should change each time you do new translation ? Maybe PO-Revision-Date could be the problem because I´m writing my .po and .mo in Brasil and the server is in Europe so the date is always old for the european server. – J.BizMai Apr 26 '19 at 12:05
1

After 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 :

  1. Which language is called thanks with get_locale()
  2. 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.org 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.org, 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.

  • I think the answer deserves a +1. And I'm glad you got the solution. :) – Sally CJ Apr 26 '19 at 16:16

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.