Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Localized page  (Read 4984 times)

0 Members and 1 Guest are viewing this topic.

almn

  • Guest
Localized page
« on: March 22, 2007, 05:45:56 PM »
Hello,

I would like to know how to detect the language of the computer that the visitor is using and depending on the language go to a certain page.

Thanks

Al968

Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: Localized page
« Reply #1 on: March 22, 2007, 05:52:52 PM »
There are several different ways to do this.  The Apache web server has the feature built in, so when configured correctly, English users will be redirected to, say, index.html.en, and German users will be redirected to index.html.de.

Or you can do the detection via server side scripting.  What's your setup?
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos

almn

  • Guest
Re: Localized page
« Reply #2 on: March 22, 2007, 06:46:03 PM »
I don't know my setup so I would rather do it by server side scripting, however may I ask which language does it require ? Php or something else ?

Thanks

Al968

Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: Localized page
« Reply #3 on: March 22, 2007, 07:43:51 PM »
I can only tell you about PHP, since that's my coding language of preference.  But the principle should apply to any server-side scripting that can inspect headers.

The $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable should tell you what locale the user's browser is reporting, and you can adjust your response accordingly (with a select statement or whatever).
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos

Computer Hope Admin

  • Administrator


  • Prodigy

    Thanked: 248
    • Yes
    • Yes
    • Yes
    • Computer Hope
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 10
Re: Localized page
« Reply #4 on: March 23, 2007, 12:52:38 PM »
There are also javascripts that could be used to detect language and forward users according to language to the appropriate location.

Below is a link to an example I found doing a quick search in Google for "javascript language detect script"

http://www.javascriptkit.com/script/script2/language.shtml

Javascript can just be inserted into your HTML.
« Last Edit: March 23, 2007, 12:53:13 PM by admin »
Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
-Albert Einstein

almn

  • Guest
Re: Localized page
« Reply #5 on: March 23, 2007, 01:16:53 PM »
Quote
I can only tell you about PHP, since that's my coding language of preference.  But the principle should apply to any server-side scripting that can inspect headers.
 
The $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable should tell you what locale the user's browser is reporting, and you can adjust your response accordingly (with a select statement or whatever).

Thanks, Can you be more precice as I don't know Php at all, maybe a tutorial ?

Thanks

Al968

Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: Localized page
« Reply #6 on: March 24, 2007, 12:54:12 PM »
This would be a somewhat advanced thing to do in any language, so it would help to use a language that you're already familiar with - or if you haven't used one before, consider doing a basic tutorial first.

I can give you some code, but you'll need a handle on how to use it.  How would you like to proceed?
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos

almn

  • Guest
Re: Localized page
« Reply #7 on: March 24, 2007, 01:51:59 PM »
I think that I can handle the basics (I may be wrong) so you go ahead and give me the code ?

Thank You for your help

Al968

Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: Localized page
« Reply #8 on: March 26, 2007, 07:44:42 AM »
An example, anywhere in your HTML.

Code: [Select]
<?php
switch ($_SERVER['HTTP_ACCEPT_LANGUAGE'])
{
  case 
'de':
    echo 
'Willkommen';
    break;
  case 
'es':
    echo 
'Recepción';
    break;:
  case 
'fr'
    
echo 'Bienvenue';
    break;
  case 
'it':
    echo 
'Benvenuto';
    break;
  default:
    echo 
'Welcome';
}
?>
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos