You are here

function geoip_language_detect_language in GeoIP API 7

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

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

Return value

string Language as ISO 639-1 Code

1 call to geoip_language_detect_language()
geoip_language_negotiation in geoip_language/geoip_language.module
Identify language via URL prefix or domain excluding administrative paths. Try to keep as light weight as possible

File

geoip_language/geoip_language.module, line 273
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;
}