Saturday 15 January 2011

How to switch language in WordPress "on-the-fly" -


Is there a way to change the language in WordPress like switch_to_blog ()

Something like this

  global $ locale $ currentLanguage = $ locale; Switch_to_language ('de_DE'); // Take some action with german localization switch_to_language ($ currentLanguage);   

Is it possible in WordPress normally?

So I finally got the solution to the function load_textdomain ()

It is said to be on my side how to define LANGUAGE_PATH and the language you want to switch to $ new_language $ your_domain is the text domain of your plugin / theme

  // Output "Good Morning" _e ('Good Morning', $ your_domain); Global $ locale; // Save the current $ current_language = $ locale for the current language; $ New_language = 'DE_de'; // Load new text domain load_testdomain ($ your_language_domain, LANGUAGE_PATH. '/'. $ Your_domain. '-'. $ New_language. 'Mo'); // Take some action with new localization / Output "Guten Morgan" _e ('Good Morning', $ your_domain); // Back to previous language load_textdomain ($ your_language_domain, LANGUAGE_PATH. '/'. $ Your_domain. '-'. $ Current_language. '.' Mo ');   

It took some time to find this method in the core. Read more about that function

No comments:

Post a Comment