admin管理员组文章数量:1314496
I wrote a plugin that I translated from English to German. The German translation only shows up, when I change the site's language to german. Once the site language is set to German, it will always show german. No matter whether I changed my profile language to English or not. And vice versa - when I set my site language to english, it will always show the English version of the plugin. All other plugins follow the profile language and show the correct language as expected. I looked at a ton of other plugins and followed the translation guidelines to the t. I don't know where the error lies and desperately need some help with this (probably rookie) error. Thank you guys so much in advance!
I wrote a plugin that I translated from English to German. The German translation only shows up, when I change the site's language to german. Once the site language is set to German, it will always show german. No matter whether I changed my profile language to English or not. And vice versa - when I set my site language to english, it will always show the English version of the plugin. All other plugins follow the profile language and show the correct language as expected. I looked at a ton of other plugins and followed the translation guidelines to the t. I don't know where the error lies and desperately need some help with this (probably rookie) error. Thank you guys so much in advance!
Share Improve this question asked Nov 26, 2020 at 5:04 SkymonkeySkymonkey 111 bronze badge1 Answer
Reset to default 1I found the solution:
In the constructor I had to add this
public function __construct()
{
// your code goes here
add_action( 'plugins_loaded', [$this, 'load_text_domain'] );
// your code goes here
}
public function load_text_domain() : void
{
load_plugin_textdomain('your-plugin-textdomain');
}
This finally made sure that the language displayed followed the settings of the user profile and not that of the website language settings. Of course you have to write your own classes constructor. Just make sure it adds the action 'plugins_loaded' with the call to the public function that loads the plugin text domain and you are good to go.
本文标签: translationPlugin language always shows WP site languagenot profile language
版权声明:本文标题:translation - Plugin language always shows WP site language, not profile language 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963373a2407411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论