global $language not working in custom module I have a custom module which I want to check the language code of the current interface language, So I added a helper function to the mymodule.module file. 

It didn't work in mymodule when I call it, It returned nothing. But If I added this function to my template.php in the mytheme directory it works like a charm and return the language code for the current interface.

I am guesting that its related to the current weight of the module in the system table, What do you think? 

function language_code(){
  global $language;
  return $language-&gt;language;
}


For additional debugging I used dpm($language); after defining global $language; in mymodule it didn't return the language array.
drupal has a function that return default language language_default with the below code

    function language_default($property = NULL) {
  $language = variable_get('language_default', (object) array('language' =&gt; 'en', 'name' =&gt; 'English', 'native' =&gt; 'English', 'direction' =&gt; 0, 'enabled' =&gt; 1, 'plurals' =&gt; 0, 'formula' =&gt; '', 'domain' =&gt; '', 'prefix' =&gt; '', 'weight' =&gt; 0, 'javascript' =&gt; ''));
  return $property ? $language-&gt;$property : $language;
}


I suggest you in hook_init(maybe your fuction not called or problem realated to your fuction)  call this function

function yourmodulename_init() {
  dsm(language_default());
  global $language;
  dsm($language);
}


According drupal documentation , $language is global variable , you problem is some strange .

I thnik problem is in your function and method of calling function. by default if you put a function in module and your module enabled(after clear cache) ,the function globaly exist and you can use it everywhere (even in views on anywhere you think).

If dsm in hook_init return $language value  I suggest you test your function

function my_language_code(){
  global $language;
  return $language-&gt;language;


}

in very where you want

$lang=my_language_code();
dsm($lang);


test this please