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.