You are here

function geoip_language_detect_language in GeoIP API 6

Same name and namespace in other branches
  1. 7 geoip_language/geoip_language.module \geoip_language_detect_language()

Return the language object mapped to the current GeoIP detected country.

1 call to geoip_language_detect_language()
geoip_language_negotiation in geoip_language/geoip_language.module
Determine the appropriate language based on path prefix, with fallbacks for user preferred language and GeoIP mapped language.

File

geoip_language/geoip_language.module, line 251
Language negotiation based on GeoIP detection.

Code

function geoip_language_detect_language($reset = FALSE) {
  static $geoip_language = NULL;
  if ($reset || !isset($geoip_language)) {

    // Get a list of enabled languages.
    $languages = language_list('enabled');
    $languages = $languages[1];

    // Get a list of country->language mappings.
    $mappings = geoip_language_mappings();

    // GeoIP detect the current country.
    $country_code = geoip_country_code();

    // Make sure country_code, the mapping for that country_code, and the enabled
    // language for that mapping, all exist.
    if ($country_code && $mappings[$country_code] && $languages[$mappings[$country_code]->language]) {
      $geoip_language = $languages[$mappings[$country_code]->language];
    }
    else {
      $geoip_language = language_default();
    }
  }
  return $geoip_language;
}