admin管理员组文章数量:1122846
I have successfully translated a child theme, but not the same result in mu-plugins folder.
The name of the plugin is "mu-functions.php". In this file I have added the "Text Domain: mu-functions" in the header and then I have loaded the textdomain:
add_action( 'plugins_loaded', 'myplugin_muload_textdomain' );
function myplugin_muload_textdomain() {
load_muplugin_textdomain( 'mu-functions', basename( dirname(__FILE__) ) . '/inc/languages' );
}
The structure of the plugin that I have created in the mu-plugins directory is the following:
In the same directory I have a "inc"(include) folder where I put all the other files that are being called through the "include_once()" function in "mu-function.php" file. Along with this files, in the same "inc" folder directory, I have the "languages" folder where I have created the "mu-functions.pot" file that has been translated to Portuguese and then generated to both ".mo" and ".po" files.
In my child theme I had an issue with these ".mo" and ".po" files. I have found in another forum that I had to name them only by the locale (so in this case "pt_PT") and not "Text-Domain-pt_PT". This issue has been successfully solved. Being so, for testing purposes I have generated 2 more other ".mo" and ".po" files. These are the files that are in my languages folder:
- mu-functions-pt_PT.mo
- mu-functions-pt_PT.po
- mu-functions.pot
- pt_PT.mo
- pt_PT.po
Can anybody, please, help me? What am I missing?
I have successfully translated a child theme, but not the same result in mu-plugins folder.
The name of the plugin is "mu-functions.php". In this file I have added the "Text Domain: mu-functions" in the header and then I have loaded the textdomain:
add_action( 'plugins_loaded', 'myplugin_muload_textdomain' );
function myplugin_muload_textdomain() {
load_muplugin_textdomain( 'mu-functions', basename( dirname(__FILE__) ) . '/inc/languages' );
}
The structure of the plugin that I have created in the mu-plugins directory is the following:
In the same directory I have a "inc"(include) folder where I put all the other files that are being called through the "include_once()" function in "mu-function.php" file. Along with this files, in the same "inc" folder directory, I have the "languages" folder where I have created the "mu-functions.pot" file that has been translated to Portuguese and then generated to both ".mo" and ".po" files.
In my child theme I had an issue with these ".mo" and ".po" files. I have found in another forum that I had to name them only by the locale (so in this case "pt_PT") and not "Text-Domain-pt_PT". This issue has been successfully solved. Being so, for testing purposes I have generated 2 more other ".mo" and ".po" files. These are the files that are in my languages folder:
- mu-functions-pt_PT.mo
- mu-functions-pt_PT.po
- mu-functions.pot
- pt_PT.mo
- pt_PT.po
Can anybody, please, help me? What am I missing?
Share Improve this question edited Dec 11, 2016 at 4:48 bravokeyl 3,3776 gold badges27 silver badges33 bronze badges asked Dec 10, 2016 at 21:55 Eduardo LeãoEduardo Leão 314 bronze badges2 Answers
Reset to default 0You need to use another action when in a mu-plugins.
add_action('muplugins_loaded', 'myplugin_muload_textdomain');
plugins_loaded
action work only after active plugins and pluggable functions are loaded.
mu-plugins are not regular plugins and will not be loaded like them.
As you can see in the following link, mu-plugins are loaded before anything else. Actions Run During a Typical Request
The problem was the line:
load_muplugin_textdomain( 'mu-functions', basename( dirname(__FILE__) ) . '/inc/languages' );
and more specifically the function:
basename( dirname(__FILE__) )
Since my plugin and language folder is in the root of mu-plugins folder, the correct code is:
load_muplugin_textdomain( 'mu-functions', 'lang' );
I've found more info in that in the following links: https://codex.wordpress.org/Function_Reference/plugins_url http://thedaneshproject.com/posts/what-does-dirname__file__-and-basenamedirname__file__-do/
I guess I have to play more to understand it if I want to put my plugin as a subdirectory mu-plugin folder.
Sorry for the delay Benoti, and thank you for the support!
本文标签: Translation of plugin in MUPLUGINS directory not working
版权声明:本文标题:Translation of plugin in MU-PLUGINS directory not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296021a1929696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论