While building a wordpress theme that has multilingual support, I needed to know what the current language was for fixing some static parts of my template.
After searching a bit on the WPML site, I found a code example where you are shown howto create your own language selector menu:
http://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
I then wrote this function to get the current language of a site:
/**
* Function for getting the active language of the WPML plugin
* @return the currently active language, defaulting to 'en'
*/
function getActiveLanguage() {
// fetches the list of languages
$languages = icl_get_languages('skip_missing=N&orderby=KEY&order=DIR');
$activeLanguage = 'en';
// runs through the languages of the system, finding the active language
foreach($languages as $language) {
// tests if the language is the active one
if($language['active'] == 1) {
$activeLanguage = $language['language_code'];
}
}
return $activeLanguage;
}
?>
Just add this code to the theme's functions.php file and you are ready to find the active language of your site!
Have a look here:
http://wpml.org/documentation/support/wpml-coding-api/
Under Language constants, you will find several constants that tell you the current language in different formats.
Odd, thought I had searched their site for help.
Thanks for the tip!
Just for clarification, what their api suggests is using the ICL_LANGUAGE_CODE constant.