I am writing a new custom module which is dependent on geoip module. I'm trying to add another language negotiation in the language detection configurations which would trigger a callback function defined in the module. Now How do I call the function defined in geoip.module file? I tried calling the function directly and after a module_load_include and both do not work.
/**
* Implement hook_language_negotiation_info
*/
function my_module_language_negotiation_info() {
return array(
'geoip_language_provider' => array(
'callbacks' => array(
'language' => '_my_module_language_callback',
),
'file' => drupal_get_path( 'module', 'my_module' ) . '/my_module.module',
'weight' => -4,
'name' => t( 'My Module GeoIP Negotiation Provider' ),
'description'=> t( 'This redirects the user to correct language based on their IP.' ),
'cache' => 0,
),
);
}
function _my_module_language_callback() {
module_load_include( 'module', 'geoip' );
//Returns array of languages based on country code. Eg. array( 'CN' => 'zh-hans',)
$languages = _my_module_language_mapping();
$country_code = geoip_country_code();
$default_langcode = language_default( 'language' );
if( !isset( $languages[$country_code] ) ) {
watchdog( 'geoip_language', 'The country code is not in the language mapping.' );
return $default_langcode;
}
return $languages[$country_code];
}