global $language not working in custom module
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