admin管理员组文章数量:1024603
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.
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- 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 Commented Apr 25, 2019 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 Commented Apr 25, 2019 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 Commented Apr 25, 2019 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 Commented Apr 25, 2019 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 Commented Apr 26, 2019 at 12:05
1 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.
本文标签: New plugin translation does not work
版权声明:本文标题:New plugin translation does not work 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745547647a2155469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.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