1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Looking for a code to autodetect/display site in visitors language

Discussion in 'Programming' started by crille30, Aug 12, 2015.

  1. #1
    Hi
    I try to find a way so when my customer come to my site landing page it will show in the language they coming from, mean based on there computer language setting or IP number. is there such a script/code.
     
    crille30, Aug 12, 2015 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #2
    Assuming that IP equals language is not going to get you anywhere. Do not make that mistake. As an example, in Belgium they speak Dutch, German and French. How can you distinguish which language the user from that country speaks? You can't. Same is true for Canada, Switzerland and a bunch of other countries. Just give your users the option to chose the language they want to view your site in. (A drop down menu with a language selection would do).
     
    qwikad.com, Aug 14, 2015 IP
    deathshadow and ketting00 like this.
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    I definitely have to second that -- just don't even go there.

    Between proxies, hosting providers that straddle multiple nations within the same IP address blocks, (half the time most attempts at doing that to my hosting reports me as being one country over in the middle of french speaking canada -- a good haul from New Hampshire), Countries where there's more than one language in common use...

    Pulling those types of stunts is just ASKING for it to fail and to piss off some user somewhere at some time.
     
    deathshadow, Aug 15, 2015 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    You can attempt to pick up the user language based on what language preference they have their browser on (usually that translates into the language they prefer):

    JS:
    
    var language = window.navigator.userLanguage || window.navigator.language;
    alert(language);//works IE/SAFARI/CHROME/FF
    
    Code (markup):
    PHP:
    
    echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    
    Code (markup):
    That is true in some sense, but you can always assume (which is true to an extreme extent) that if someone lives in Belgium that they can speak its official language. There are a few exceptions to such rule but they are pretty low.
     
    ThePHPMaster, Aug 16, 2015 IP
  5. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #5
    I suppose, but it still can be a mess. The OS's with IE browsers (IE 11) will return .userLanguage as the language of that OS and not that of the browser. Worth trying though, if that's what the OP really wants (as opposed to a drop down menu).
     
    qwikad.com, Aug 16, 2015 IP