Location: PHPKode > scripts > Colossal Mind Language Detector > example-1.php
<?php


ini_set('display_errors',1);


// Example 1
// Only detecting language. Page does not reload.


//----------------------------------------------------------------------
// SETTINGS: I am sure you'll want to change them to suit your needs!


// MAP browser header Accept-Language to language
// is used for detecting language setting from browser's
// Accept-Language header
$lang_params['LANG_LANG_MAP'] = array(
							'en*' => 'en_GB',
							'de*' => 'de_DE',
							'cs*' => 'cs_CZ',
							'sk*' => 'cs_CZ',
							'it*' => 'it_IT',
							'nl*' => 'nl_NL',
							'fr*' => 'fr_FR',
							'es*' => 'es_ES',
							'pt*' => 'pt_PT'
							);

// OPTIONAL but recommended if your system can detect country from IP address.
// MAP country code to language
// If you don't want to use this, don't define it.
$lang_params['LANG_GEO_MAP'] = array(
							'at' => 'de_DE', // Austria
							'ch' => 'de_DE', // Switzerland
							'de' => 'de_DE', // Germany
							'li' => 'de_DE', // Liechtenstein
							'cz' => 'cs_CZ', // Czech Republic
							'sk' => 'cs_CZ', // Slovakia
							'it' => 'it_IT', // Italy
							'nl' => 'nl_NL', // Netherlands
							'be' => 'fr_FR', // Belgium
							'fr' => 'fr_FR', // France
							'mc' => 'fr_FR', // Monaco
							'lu' => 'fr_FR', // Luxembourg
							're' => 'fr_FR', // Reunion
							'es' => 'es_ES', // Spain
							'co' => 'es_ES', // Colombia
							'pe' => 'es_ES', // Peru
							've' => 'es_ES', // Venezuela
							'ec' => 'es_ES', // Ecuador
							'gt' => 'es_ES', // Guatemala
							'cu' => 'es_ES', // Cuba
							'bo' => 'es_ES', // Bolivia
							'hn' => 'es_ES', // Honduras
							'py' => 'es_ES', // Paraguay
							'sv' => 'es_ES', // El Salvador
							'cr' => 'es_ES', // Costa Rica
							'pa' => 'es_ES', // Panama
							'gq' => 'es_ES', // Equatorial Guinea
							'mx' => 'es_ES', // Mexico
							'ar' => 'es_ES', // Argentina
							'cl' => 'es_ES', // Chile
							'do' => 'es_ES', // Dominican Republic
							'ni' => 'es_ES', // Nicaragua
							'uy' => 'es_ES', // Uruguay
							'pt' => 'pt_PT', // Portugal
							'br' => 'pt_PT', // Brazil
							'mz' => 'pt_PT', // Mozambique
							'ao' => 'pt_PT', // Angola
							'gw' => 'pt_PT', // Guinea-Bissau
							'tl' => 'pt_PT', // East Timor
							'cv' => 'pt_PT', // Cape Verde
							'st' => 'pt_PT' // São Tomé and Príncipe
							);

// Default language
// If you leave it empty or not define it, default will be en_GB.
$lang_params['LANGUAGE_DEFAULT'] = 'en_GB'; // Example 'fr_CA' (French language, Canada)

// If you can tell me which country the user is in, then plug the 2-letter code here.
// There are number of systems (or classes) available that convert IP address to country code.
// You can leave it empty (or not define it) and this class will work fine.
$lang_params['COUNTRY_CODE'] = 'us'; // case-insensitive

// If you enable to use cookie for storing the language value, any
// subsequent language detection will be faster and more likely correct.
// If you leave it empty or not define it, default will be false (not use cookie).
$lang_params['USE_COOKIE'] = true;

// OPTIONAL: Name of the language cookie.
// If you leave it empty or not define it, default will be 'CMLANG'.
$lang_params['COOKIE_NAME'] = 'CMLANG';

//----------------------------------------------------------------------


require('class.colossal-mind-language-detector.php');
$cmldet = new colossal_mind_language_detector($lang_params);
$language = $cmldet->detect_language();

echo 'Accept-Language header: '.$_SERVER['HTTP_ACCEPT_LANGUAGE'].'<br /><br />';
echo 'Language code: '.$language[0].'<br />';
echo 'Method: '.$language[1].'<br />';


// When you are done with debugging, you can get rid of the output array like this
//$language_code = reset($cmldet->detect_language());



?>
Return current item: Colossal Mind Language Detector