I have English and Deutch languages, WordPress 6.0. I programmatically set the language using switch_to_locale('de_DE'); (depends on URL).
add_action( 'plugin_loaded', 'set_lang');
function set_lang() {
switch_to_locale('de_DE');
}
Everything translates except menu items.
Menu items are translated if I set ?lang=de in the URL or execute $REQUEST['lang'] = 'de'; in hook plugins_loaded
This solution works but does not look correct. Tell me, please, how to programmatically set the language more correctly so that the menu is also translated.
I use Max Mega Menu and WP Multilang for Translation. I tried to use another template and menu plugin but it doesn't change language.
I tried to use add_filter('locale', .. ) but it doesn't help.
I tried to use switch_to_locale() in another hooks but it doesn`t help.
Thank you very much for your attention, I will be glad to solve my problem! Hope this helps more than just me.