tmp solution for my case is adding another hook:
add_action('pll_language_defined', function ($slug) {
$_COOKIE['pll_language'] = $slug;
});
same issue here…
In my case the mo files replaced by Messages_Translation::load_textdomain_mofile hook which is get PLL cookie, but the cookie is set at the end of request, so for lang-switch requests we have old cookie value so your hook replaces mo-filenames with previously active language.
could you explain this hook’s comment?
// whyever this does not work out of the box, especially in AJAX
I think, such way to replace mo-filenames is not too good idea and can cause more problems later. Imho it is better to research the original problem(which “solved” by the hook) and try to solve it w/o such hacks. Could you describe the original problem plz so I can debug it or so…
Thank you!