You are here

function ip_language_negotiation_from_ip in IP Language Negotiation 7

Callback function for ip_language_negotiation_language_negotiation_info().

1 string reference to 'ip_language_negotiation_from_ip'
ip_language_negotiation_language_negotiation_info in ./ip_language_negotiation.module
Implements hook_language_negotiation_info().

File

./ip_language_negotiation.module, line 49
Main module file for the IP Language Negotiation.

Code

function ip_language_negotiation_from_ip($languages) {

  // Disable caching for this page. This only happens when negotiating
  // based on IP. Once the redirect took place to the correct domain
  // or language prefix, this function is not reached anymore and
  // caching works as expected.
  drupal_page_is_cacheable(FALSE);
  $current_ip = ip_address();
  $language_settings = variable_get('ip_language_negotiation_countries', array());
  drupal_load('module', 'ip2country');

  // Check for debug settings. If enabled, use it.
  if (variable_get('ip2country_debug', 0) == 1) {
    if (variable_get('ip2country_test_type', 0) == 0) {

      // Debug Country entered.
      $country_code = variable_get('ip2country_test_country', 'US');
    }
    else {

      // Debug IP entered.
      $ip = variable_get('ip2country_test_ip_address', $current_ip);
      $country_code = ip2country_get_country($ip);
    }
  }
  else {

    // Check if the country code can be determined by the IP.
    $country_code = ip2country_get_country($current_ip);
  }
  if (!empty($country_code)) {

    // Check if a language is set for the determined country.
    if (!empty($language_settings[$country_code])) {
      return $language_settings[$country_code];
    }
  }
}