Cloudflare country code for language negotiation Cloudflare.com provides CF_IPCountry http header.
This can be retrieved in php with

$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; 


as they say. It'll return XX if the country cannot be determined. 

How can this header be used to negotiate language?
(I want to use it so that if users come for example from France, then to be redirected t www.site.com/fr/ homepage, and if they come for any other country in the world go to www.site.com/en/ homepage?)

My research:
There are 2 modules for Drupal 7, but I don't think they can do what I want.

One module is http://drupal.org/project/ip2locale, which is dev version and not updated for a year, and the other is http://drupal.org/project/smart_ip, which says it breaks caching because it adds session variable.
They both don't use cloudflare as source of ip.

Is there any php snippet that I can add somewhere, so that $_SERVER["HTTP_CF_IPCOUNTRY"] takes me to the locale I want?

If you ask me why I want to use cloudflare header, I suppose that maybe it's faster to determine country and more updated with ips, than other free solutions.

Thanks
Drupal provides a hook for those module that implements a new method for detecting the language to use: hook_language_negotiation_info(). This hook gets information about some callbacks, including the one that returns the language ID.
As example of hook, you can look at locale_language_negotiation_info(), and to the three callbacks used for the first provider: locale_language_from_url(), locale_language_switcher_url(), and locale_language_url_rewrite_url().

Any provider the modules implement are listed on admin/config/regional/language/configure, where the administration user can enable each of them.



The providers that are enabled are called to provide a language ID. For what I can understand code similar to the following one should work.

function mymodule_language_negotiation_info() {
  $providers = array();

  $providers['mymodule_cloudflare_provider'] = array(
    'callbacks' =&gt; array('language' =&gt; 'mymodule_language_from_cloudflare'), 
    'weight' =&gt; -4, 
    'name' =&gt; t('Cloudflare'), 
    'description' =&gt; t("Use Cloudflare to detect the language used where the user is actually located."),
  );

  return $providers;
}

function mymodule_language_from_cloudflare($languages) {
  if (isset($_SERVER["HTTP_CF_IPCOUNTRY"])) {
    $langcode = mymodule_get_langcode($_SERVER["HTTP_CF_IPCOUNTRY"]);
    if (isset($languages[$langcode])) {
      return $langcode;
    }
  }

  return FALSE;
}


mymodule_get_langcode(), the function for which I didn't write the code, should return the language code from the country code returned from Cloudflare.com.