Scripts Sederhana deteksi bahasa pengunjung.

cara sederhana mendeteksi bahasa pengunjung.. dengan deteksi variable reguest yang dikirim oleh browser pengunjung.
nih contoh scripts sederhana dengan memake $_SERVER["HTTP_ACCEPT_LANGUAGE"]

<?php

$prefix = array(
array('country'=>'Afrikaans' ,'code'=>'af'),
array('country'=>'Albanian' ,'code'=>'sq'),
array('country'=>'Arabic (Algeria)' ,'code'=>'ar-dz'),
array('country'=>'Arabic (Bahrain)' ,'code'=>'ar-bh'),
array('country'=>'Arabic (Egypt)' ,'code'=>'ar-eg'),
array('country'=>'Arabic (Iraq)' ,'code'=>'ar-iq'),
array('country'=>'Arabic (Jordan)' ,'code'=>'ar-jo'),
array('country'=>'Arabic (Kuwait)' ,'code'=>'ar-kw'),
array('country'=>'Arabic (Lebanon)' ,'code'=>'ar-lb'),
array('country'=>'Arabic (libya)' ,'code'=>'ar-ly'),
array('country'=>'Arabic (Morocco)' ,'code'=>'ar-ma'),
array('country'=>'Arabic (Oman)' ,'code'=>'ar-om'),
array('country'=>'Arabic (Qatar)' ,'code'=>'ar-qa'),
array('country'=>'Arabic (Saudi Arabia)' ,'code'=>'ar-sa'),
array('country'=>'Arabic (Syria)' ,'code'=>'ar-sy'),
array('country'=>'Arabic (Tunisia)' ,'code'=>'ar-tn'),
array('country'=>'Arabic (U.A.E.)' ,'code'=>'ar-ae'),
array('country'=>'Arabic (Yemen)' ,'code'=>'ar-ye'),
array('country'=>'Arabic' ,'code'=>'ar'),
array('country'=>'Armenian' ,'code'=>'hy'),
array('country'=>'Assamese' ,'code'=>'as'),
array('country'=>'Azeri (Cyrillic)' ,'code'=>'az'),
array('country'=>'Azeri (Latin)' ,'code'=>'az'),
array('country'=>'Basque' ,'code'=>'eu'),
array('country'=>'Belarusian' ,'code'=>'be'),
array('country'=>'Bengali' ,'code'=>'bn'),
array('country'=>'Bulgarian' ,'code'=>'bg'),
array('country'=>'Catalan' ,'code'=>'ca'),
array('country'=>'Chinese (China)' ,'code'=>'zh-cn'),
array('country'=>'Chinese (Hong Kong SAR)' ,'code'=>'zh-hk'),
array('country'=>'Chinese (Macau SAR)' ,'code'=>'zh-mo'),
array('country'=>'Chinese (Singapore)' ,'code'=>'zh-sg'),
array('country'=>'Chinese (Taiwan)' ,'code'=>'zh-tw'),
array('country'=>'Chinese' ,'code'=>'zh'),
array('country'=>'Croatian' ,'code'=>'hr'),
array('country'=>'Chech' ,'code'=>'cs'),
array('country'=>'Danish' ,'code'=>'da'),
array('country'=>'Divehi' ,'code'=>'div'),
array('country'=>'Dutch (Belgium)' ,'code'=>'nl-be'),
array('country'=>'Dutch (Netherlands)' ,'code'=>'nl'),
array('country'=>'English (Australia)' ,'code'=>'en-au'),
array('country'=>'English (Belize)' ,'code'=>'en-bz'),
array('country'=>'English (Canada)' ,'code'=>'en-ca'),
array('country'=>'English (Caribbean)' ,'code'=>'en'),
array('country'=>'English (Ireland)' ,'code'=>'en-ie'),
array('country'=>'English (Jamaica)' ,'code'=>'en-jm'),
array('country'=>'English (New Zealand)' ,'code'=>'en-nz'),
array('country'=>'English (Philippines)' ,'code'=>'en-ph'),
array('country'=>'English (South Africa)' ,'code'=>'en-za'),
array('country'=>'English (Trinidad)' ,'code'=>'en-tt'),
array('country'=>'English (United Kingdom)' ,'code'=>'en-gb'),
array('country'=>'English (United States)' ,'code'=>'en-us'),
array('country'=>'English (Zimbabwe)' ,'code'=>'en-zw'),
array('country'=>'English' ,'code'=>'en'),
array('country'=>'Estonian' ,'code'=>'et'),
array('country'=>'Faeroese' ,'code'=>'fo'),
array('country'=>'Farsi' ,'code'=>'fa'),
array('country'=>'Finnish' ,'code'=>'fi'),
array('country'=>'French (Belgium)' ,'code'=>'fr-be'),
array('country'=>'French (Canada)' ,'code'=>'fr-ca'),
array('country'=>'French (France)' ,'code'=>'fr'),
array('country'=>'French (Luxembourg)' ,'code'=>'fr-lu'),
array('country'=>'French (Monaco)' ,'code'=>'fr-mc'),
array('country'=>'French (Switzerland)' ,'code'=>'fr-ch'),
array('country'=>'FYRO Macedonian' ,'code'=>'mk'),
array('country'=>'Gaelic' ,'code'=>'gd'),
array('country'=>'Georgian' ,'code'=>'ka'),
array('country'=>'German (Austria)' ,'code'=>'de-at'),
array('country'=>'German (Germany)' ,'code'=>'de'),
array('country'=>'German (Liechtenstein)' ,'code'=>'de-li'),
array('country'=>'German (lexumbourg)' ,'code'=>'de-lu'),
array('country'=>'German (Switzerland)' ,'code'=>'de-ch'),
array('country'=>'Greek' ,'code'=>'el'),
array('country'=>'Gujarati' ,'code'=>'gu'),
array('country'=>'Hebrew' ,'code'=>'he'),
array('country'=>'Hindi' ,'code'=>'hi'),
array('country'=>'Hungarian' ,'code'=>'hu'),
array('country'=>'Icelandic' ,'code'=>'is'),
array('country'=>'Indonesian' ,'code'=>'id'),
array('country'=>'Italian (Italy)' ,'code'=>'it'),
array('country'=>'Italian (Switzerland)' ,'code'=>'it-ch'),
array('country'=>'Japanese' ,'code'=>'ja'),
array('country'=>'Kannada' ,'code'=>'kn'),
array('country'=>'Kazakh' ,'code'=>'kk'),
array('country'=>'Konkani' ,'code'=>'kok'),
array('country'=>'Korean' ,'code'=>'ko'),
array('country'=>'Kyrgyz' ,'code'=>'kz'),
array('country'=>'Latvian' ,'code'=>'lv'),
array('country'=>'Lithuanian' ,'code'=>'lt'),
array('country'=>'Malay (Brunei)' ,'code'=>'ms'),
array('country'=>'Malay (Malaysia)' ,'code'=>'ms'),
array('country'=>'Malayalam' ,'code'=>'ml'),
array('country'=>'Maltese' ,'code'=>'mt'),
array('country'=>'Marathi' ,'code'=>'mr'),
array('country'=>'Mongolian (Cyrillic)' ,'code'=>'mn'),
array('country'=>'Nepali (India)' ,'code'=>'ne'),
array('country'=>'Norwegian (Bokmal)' ,'code'=>'nb-no'),
array('country'=>'Norwegian (Bokmal)' ,'code'=>'no'),
array('country'=>'Norwegian (Nynorsk)' ,'code'=>'nn-no'),
array('country'=>'Oriya' ,'code'=>'or'),
array('country'=>'Polish' ,'code'=>'pl'),
array('country'=>'Portuguese (Brazil)' ,'code'=>'pt-br'),
array('country'=>'Portuguese (Portugal)' ,'code'=>'pt'),
array('country'=>'Punjabi' ,'code'=>'pa'),
array('country'=>'Rhaeto-Romanic' ,'code'=>'rm'),
array('country'=>'Romanian (Moldova)' ,'code'=>'ro-md'),
array('country'=>'Romanian' ,'code'=>'ro'),
array('country'=>'Russian (Moldova)' ,'code'=>'ru-md'),
array('country'=>'Russian' ,'code'=>'ru'),
array('country'=>'Sanskrit' ,'code'=>'sa'),
array('country'=>'Serbian (Cyrillic)' ,'code'=>'sr'),
array('country'=>'Serbian (Latin)' ,'code'=>'sr'),
array('country'=>'Slovak' ,'code'=>'sk'),
array('country'=>'Slovenian' ,'code'=>'ls'),
array('country'=>'Sorbian' ,'code'=>'sb'),
array('country'=>'Spanish (Argentina)' ,'code'=>'es-ar'),
array('country'=>'Spanish (Bolivia)' ,'code'=>'es-bo'),
array('country'=>'Spanish (Chile)' ,'code'=>'es-cl'),
array('country'=>'Spanish (Colombia)' ,'code'=>'es-co'),
array('country'=>'Spanish (Costa Rica)' ,'code'=>'es-cr'),
array('country'=>'Spanish (Dominican Republic)' ,'code'=>'es-do'),
array('country'=>'Spanish (Ecuador)' ,'code'=>'es-ec'),
array('country'=>'Spanish (El Salvador)' ,'code'=>'es-sv'),
array('country'=>'Spanish (Guatemala)' ,'code'=>'es-gt'),
array('country'=>'Spanish (Honduras)' ,'code'=>'es-hn'),
array('country'=>'Spanish (International Sort)' ,'code'=>'es'),
array('country'=>'Spanish (Mexico)' ,'code'=>'es-mx'),
array('country'=>'Spanish (Nicaragua)' ,'code'=>'es-ni'),
array('country'=>'Spanish (Panama)' ,'code'=>'es-pa'),
array('country'=>'Spanish (Paraguay)' ,'code'=>'es-py'),
array('country'=>'Spanish (Peru)' ,'code'=>'es-pe'),
array('country'=>'Spanish (Puerto Rico)' ,'code'=>'es-pr'),
array('country'=>'Spanish (Traditional Sort)' ,'code'=>'es'),
array('country'=>'Spanish (United States)' ,'code'=>'es-us'),
array('country'=>'Spanish (Uruguay)' ,'code'=>'es-uy'),
array('country'=>'Spanish (Venezuela)' ,'code'=>'es-ve'),
array('country'=>'Sutu' ,'code'=>'sx'),
array('country'=>'Swahili' ,'code'=>'sw'),
array('country'=>'Swedish (Finland)' ,'code'=>'sv-fi'),
array('country'=>'Swedish' ,'code'=>'sv'),
array('country'=>'Syriac' ,'code'=>'syr'),
array('country'=>'Tamil' ,'code'=>'ta'),
array('country'=>'Tatar' ,'code'=>'tt'),
array('country'=>'Telugu' ,'code'=>'te'),
array('country'=>'Thai' ,'code'=>'th'),
array('country'=>'Tsonga' ,'code'=>'ts'),
array('country'=>'Tswana' ,'code'=>'tn'),
array('country'=>'Turkish' ,'code'=>'tr'),
array('country'=>'Ukrainian' ,'code'=>'uk'),
array('country'=>'Urdu' ,'code'=>'ur'),
array('country'=>'Uzbek (Cyrillic)' ,'code'=>'uz'),
array('country'=>'Uzbek (Latin)' ,'code'=>'uz'),
array('country'=>'Vietnamese' ,'code'=>'vi'),
array('country'=>'Xhosa' ,'code'=>'xh'),
array('country'=>'Yiddish' ,'code'=>'yi'),
array('country'=>'Zulu' ,'code'=>'zu')
);

//DETEK LANGUAGE
$acceptlanguage = explode(",",strtolower(@$_SERVER["HTTP_ACCEPT_LANGUAGE"]));
for ($i=0;$i& lt;count($prefix);$i++){
if (preg_match('/'.$prefix[$i]['code'].'/', $acceptlanguage[0])) {
$language = $prefix[$i]['country'];
}
}

echo $language;
?>

0 Response to "Scripts Sederhana deteksi bahasa pengunjung."