Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:54:59+00:00 2026-06-05T00:54:59+00:00

Possible Duplicate: JavaScript for detecting browser language preference Detect Browser Language in PHP What's

  • 0

Possible Duplicate:
JavaScript for detecting browser language preference
Detect Browser Language in PHP
What's best method to detect language?

I have created a website that anyone in the world can visit.

So, I need a way to know approximately what is the user’s language without asking them.

Obviously, there is also a link that sets the language via cookie.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:55:00+00:00Added an answer on June 5, 2026 at 12:55 am

    You can use the Accept-Language HTTP request header which is sent by every browser.

    I found this function to parse it:

    function getPreferredLanguage() {
        $langs = array();
        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            // break up string into pieces (languages and q factors)
            preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
                    $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
            if (count($lang_parse[1])) {
                // create a list like "en" => 0.8
                $langs = array_combine($lang_parse[1], $lang_parse[4]);
                // set default to 1 for any without q factor
                foreach ($langs as $lang => $val) {
                    if ($val === '') $langs[$lang] = 1;
                }
                // sort list based on value 
                arsort($langs, SORT_NUMERIC);
            }
        }
        //extract most important (first)
        foreach ($langs as $lang => $val) { break; }
        //if complex language simplify it
        if (stristr($lang,"-")) {$tmp = explode("-",$lang); $lang = $tmp[0]; }
        return $lang;
    }
    $language = getPreferredLanguage();
    

    http://snipplr.com/view.php?codeview&id=24897


    If you want the full version of it (e.g. English), you can use this array:

    $languageCodes = array(
     "aa" => "Afar",
     "ab" => "Abkhazian",
     "ae" => "Avestan",
     "af" => "Afrikaans",
     "ak" => "Akan",
     "am" => "Amharic",
     "an" => "Aragonese",
     "ar" => "Arabic",
     "as" => "Assamese",
     "av" => "Avaric",
     "ay" => "Aymara",
     "az" => "Azerbaijani",
     "ba" => "Bashkir",
     "be" => "Belarusian",
     "bg" => "Bulgarian",
     "bh" => "Bihari",
     "bi" => "Bislama",
     "bm" => "Bambara",
     "bn" => "Bengali",
     "bo" => "Tibetan",
     "br" => "Breton",
     "bs" => "Bosnian",
     "ca" => "Catalan",
     "ce" => "Chechen",
     "ch" => "Chamorro",
     "co" => "Corsican",
     "cr" => "Cree",
     "cs" => "Czech",
     "cu" => "Church Slavic",
     "cv" => "Chuvash",
     "cy" => "Welsh",
     "da" => "Danish",
     "de" => "German",
     "dv" => "Divehi",
     "dz" => "Dzongkha",
     "ee" => "Ewe",
     "el" => "Greek",
     "en" => "English",
     "eo" => "Esperanto",
     "es" => "Spanish",
     "et" => "Estonian",
     "eu" => "Basque",
     "fa" => "Persian",
     "ff" => "Fulah",
     "fi" => "Finnish",
     "fj" => "Fijian",
     "fo" => "Faroese",
     "fr" => "French",
     "fy" => "Western Frisian",
     "ga" => "Irish",
     "gd" => "Scottish Gaelic",
     "gl" => "Galician",
     "gn" => "Guarani",
     "gu" => "Gujarati",
     "gv" => "Manx",
     "ha" => "Hausa",
     "he" => "Hebrew",
     "hi" => "Hindi",
     "ho" => "Hiri Motu",
     "hr" => "Croatian",
     "ht" => "Haitian",
     "hu" => "Hungarian",
     "hy" => "Armenian",
     "hz" => "Herero",
     "ia" => "Interlingua (International Auxiliary Language Association)",
     "id" => "Indonesian",
     "ie" => "Interlingue",
     "ig" => "Igbo",
     "ii" => "Sichuan Yi",
     "ik" => "Inupiaq",
     "io" => "Ido",
     "is" => "Icelandic",
     "it" => "Italian",
     "iu" => "Inuktitut",
     "ja" => "Japanese",
     "jv" => "Javanese",
     "ka" => "Georgian",
     "kg" => "Kongo",
     "ki" => "Kikuyu",
     "kj" => "Kwanyama",
     "kk" => "Kazakh",
     "kl" => "Kalaallisut",
     "km" => "Khmer",
     "kn" => "Kannada",
     "ko" => "Korean",
     "kr" => "Kanuri",
     "ks" => "Kashmiri",
     "ku" => "Kurdish",
     "kv" => "Komi",
     "kw" => "Cornish",
     "ky" => "Kirghiz",
     "la" => "Latin",
     "lb" => "Luxembourgish",
     "lg" => "Ganda",
     "li" => "Limburgish",
     "ln" => "Lingala",
     "lo" => "Lao",
     "lt" => "Lithuanian",
     "lu" => "Luba-Katanga",
     "lv" => "Latvian",
     "mg" => "Malagasy",
     "mh" => "Marshallese",
     "mi" => "Maori",
     "mk" => "Macedonian",
     "ml" => "Malayalam",
     "mn" => "Mongolian",
     "mr" => "Marathi",
     "ms" => "Malay",
     "mt" => "Maltese",
     "my" => "Burmese",
     "na" => "Nauru",
     "nb" => "Norwegian Bokmal",
     "nd" => "North Ndebele",
     "ne" => "Nepali",
     "ng" => "Ndonga",
     "nl" => "Dutch",
     "nn" => "Norwegian Nynorsk",
     "no" => "Norwegian",
     "nr" => "South Ndebele",
     "nv" => "Navajo",
     "ny" => "Chichewa",
     "oc" => "Occitan",
     "oj" => "Ojibwa",
     "om" => "Oromo",
     "or" => "Oriya",
     "os" => "Ossetian",
     "pa" => "Panjabi",
     "pi" => "Pali",
     "pl" => "Polish",
     "ps" => "Pashto",
     "pt" => "Portuguese",
     "qu" => "Quechua",
     "rm" => "Raeto-Romance",
     "rn" => "Kirundi",
     "ro" => "Romanian",
     "ru" => "Russian",
     "rw" => "Kinyarwanda",
     "sa" => "Sanskrit",
     "sc" => "Sardinian",
     "sd" => "Sindhi",
     "se" => "Northern Sami",
     "sg" => "Sango",
     "si" => "Sinhala",
     "sk" => "Slovak",
     "sl" => "Slovenian",
     "sm" => "Samoan",
     "sn" => "Shona",
     "so" => "Somali",
     "sq" => "Albanian",
     "sr" => "Serbian",
     "ss" => "Swati",
     "st" => "Southern Sotho",
     "su" => "Sundanese",
     "sv" => "Swedish",
     "sw" => "Swahili",
     "ta" => "Tamil",
     "te" => "Telugu",
     "tg" => "Tajik",
     "th" => "Thai",
     "ti" => "Tigrinya",
     "tk" => "Turkmen",
     "tl" => "Tagalog",
     "tn" => "Tswana",
     "to" => "Tonga",
     "tr" => "Turkish",
     "ts" => "Tsonga",
     "tt" => "Tatar",
     "tw" => "Twi",
     "ty" => "Tahitian",
     "ug" => "Uighur",
     "uk" => "Ukrainian",
     "ur" => "Urdu",
     "uz" => "Uzbek",
     "ve" => "Venda",
     "vi" => "Vietnamese",
     "vo" => "Volapuk",
     "wa" => "Walloon",
     "wo" => "Wolof",
     "xh" => "Xhosa",
     "yi" => "Yiddish",
     "yo" => "Yoruba",
     "za" => "Zhuang",
     "zh" => "Chinese",
     "zu" => "Zulu"
    );
    

    http://www.fractalizer.ru/frpost_267/php-array-of-iso-639-1-language-codes-names/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript for detecting browser language preference I want to detect the language
Possible Duplicate: JavaScript for detecting browser language preference Is it possible to find from
Possible Duplicate: Client-side detection of HTTP request method I'm working on Javascript that is
Possible Duplicate: Detecting an undefined object property in JavaScript javascript undefined compare How we
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript Is there is a
Possible Duplicate: JavaScript: Know when an image is fully loaded I have this code:
Possible Duplicate: JavaScript replace all / with \ in a string? I have a
Possible Duplicate: Deleting Objects in JavaScript I have a JS object having a large
Possible Duplicate: Detecting an undefined object property in JavaScript From the below JavaScript sample,
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript I was using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.