Cloudflare country code for language negotiation
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.