PHP welcome message in viewer's language ???

This is a discussion on "PHP welcome message in viewer's language ???" within the PHP Forum section. This forum, and the thread "PHP welcome message in viewer's language ??? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 12th, 2006, 12:33
Junior Member
Join Date: Apr 2006
Age: 27
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Question PHP welcome message in viewer's language ???

One of the page from my presently under-contruction website can be seen on http://members.lycos.co.uk/darsh25/P...e/services.php

As it can be seen from the HEADER (right at the top) that I've the text-size selector (which isn't working, at the moment) along with the present date (as set in user's own computer).

Realising that such a "text-sizer" isn't quite a good idea since browser provides that facility anyway, I'm thinking to get rid-off this text-sizer and leave the "date" code as it is.

However, in the same HEADER area, I wonder if there's ANYTHING in PHP that allows to do the following:

>> Firstly, identify the "clock/time setting" in their computer and then display message saying "Good Morning/Afternoon/Evening".

>> Additionally, I would like this "Good Morning/Afternoon/Evening" appearing in viewers OWN language i.e. if he's from English speaking country then this message should appear in ENGLISH, if he's from French speaking country this message should appear in FRENCH, etc.

I've read a book few months back on PHP which said such a thing could be possible using a PHP script that identifies the "clock timing" along with the "language" set on viewers browser (or something like that).

I really DO NOT want to ask user about their language/country (and then display the message in THEIR language) since not all viewers would appreciate answering such question and beside the services of my website in itself isn't quite relevant to asking such question.

Hence, would there be anything within PHP script that identifies the relevant information (time & language/country) and then display the necessary "Welcome Message" such as:

> Good Morning, Hope you enjoy your stay (if user's location or brower setting is ENGLISH)
> Guten Morning, (same message in German) (if user's location or brower setting is GERMAN).
> Bonjour, (same message in French) (if user's location or brower setting is FRANCE/French speaking location).

Any idea, alternative thing to do instead, recommendation, help or guidance would be greatly appreciated.
Reply With Quote

  #2 (permalink)  
Old Jun 12th, 2006, 12:55
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP welcome message in viewer's language ???

There are two possible sources of information for you - there may be something in the header supplied by the browser, and there's the user's IP address. Neither is 100% reliable, but (my site) looks up the remote IP address and is between 98% and 99% accurate by country. We use Maxmind software of which there is a community (open source) version.

Problems you'll have ... multinational companies who have VPNs and who's network traffic pops out at HQ. One big Bristol company of ours keeps coming up in France, and I've a London customer who's told all about our services in Ireland ... but they're used to it on other sites and just laugh it off provided they're given a "change you country" option.

Second issue - countries like Belgium, Switzerland and Wales where several languages are spoken ....
Reply With Quote
  #3 (permalink)  
Old Jun 13th, 2006, 16:05
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP welcome message in viewer's language ???

Perhaps if you were to make use of javascript this would be easier, javascript can easly grab the local users time, as for the language, i'm sure there is a javascript function that pulls the local users language (as set by the os), you could then have the javascript access an array in a flat file, or send the data to a php script useing XMLHttpRequest or ActiveXObject.
Reply With Quote
  #4 (permalink)  
Old Jun 13th, 2006, 16:13
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP welcome message in viewer's language ???

You can certainly use php to detect a user's language. Here's one idea from PHParadise that looks to me like it should still work:

Code: Select all
001 <?php

                002 

                003 function    lixlpixel_get_env_var($Var)

                004 {

                005     if(empty($GLOBALS[$Var]))

                006     {

                007         $GLOBALS[$Var]=(!empty($GLOBALS['_SERVER'][$Var]))?

                008         $GLOBALS['_SERVER'][$Var]:

                009         (!empty($GLOBALS['HTTP_SERVER_VARS'][$Var]))?

                010         $GLOBALS['HTTP_SERVER_VARS'][$Var]:'';

                011     }

                012 }

                013  

                014 function    lixlpixel_detect_lang()

                015 {

                016     //    Detect    HTTP_ACCEPT_LANGUAGE    &    HTTP_USER_AGENT.

                017     lixlpixel_get_env_var('HTTP_ACCEPT_LANGUAGE');

                018     lixlpixel_get_env_var('HTTP_USER_AGENT');

                019     

                020     $_AL=strtolower($GLOBALS['HTTP_ACCEPT_LANGUAGE']);

                021     $_UA=strtolower($GLOBALS['HTTP_USER_AGENT']);

                022     

                023     //    Try    to    detect    Primary    language    if    several    languages    are    accepted.

                024     foreach($GLOBALS['_LANG']    as    $K)

                025     {

                026         if(strpos($_AL,    $K)===0)

                027             return    $K;

                028     }

                029     

                030     //    Try    to    detect    any    language    if    not    yet    detected.

                031     foreach($GLOBALS['_LANG']    as    $K)

                032     {

                033         if(strpos($_AL,    $K)!==false)

                034             return    $K;

                035     }

                036     foreach($GLOBALS['_LANG']    as    $K)

                037     {

                038         if(preg_match("/[\[\(    ]{$K}[;,_\-\)]/",$_UA))

                039             return    $K;

                040     }

                041     

                042     //    Return    default    language    if    language    is    not    yet    detected.

                043     return    $GLOBALS['_DLANG'];

                044 }

                045  

                046 //    Define    default    language.

                047 $GLOBALS['_DLANG']='en';

                048  

                049 //    Define    all    available    languages.

                050 //    WARNING:    uncomment    all    available    languages

                051 

                052 $GLOBALS['_LANG']    =    array(

                053         'af',    //    afrikaans.

                054         'ar',    //    arabic.

                055         'bg',    //    bulgarian.

                056         'ca',    //    catalan.

                057         'cs',    //    czech.

                058         'da',    //    danish.

                059         'de',    //    german.

                060         'el',    //    greek.

                061         'en',    //    english.

                062         'es',    //    spanish.

                063         'et',    //    estonian.

                064         'fi',    //    finnish.

                065         'fr',    //    french.

                066         'gl',    //    galician.

                067         'he',    //    hebrew.

                068         'hi',    //    hindi.

                069         'hr',    //    croatian.

                070         'hu',    //    hungarian.

                071         'id',    //    indonesian.

                072         'it',    //    italian.

                073         'ja',    //    japanese.

                074         'ko',    //    korean.

                075         'ka',    //    georgian.

                076         'lt',    //    lithuanian.

                077         'lv',    //    latvian.

                078         'ms',    //    malay.

                079         'nl',    //    dutch.

                080         'no',    //    norwegian.

                081         'pl',    //    polish.

                082         'pt',    //    portuguese.

                083         'ro',    //    romanian.

                084         'ru',    //    russian.

                085         'sk',    //    slovak.

                086         'sl',    //    slovenian.

                087         'sq',    //    albanian.

                088         'sr',    //    serbian.

                089         'sv',    //    swedish.

                090         'th',    //    thai.

                091         'tr',    //    turkish.

                092         'uk',    //    ukrainian.

                093         'zh'    //    chinese.

                094 );

                095  

                096 //    Redirect    to    the    correct    location.

                097 

                098 //    Example    Implementations

                099 

                100 //    Redirect    to    the    correct    location.

                101 //header('location:    http://www.your_site.com/index_'.lixlpixel_detect_lang().'.php');

                102 

                103 //    simply    display    the    detected    language

                104 echo    '<p>the    language    detected    is:    '.lixlpixel_detect_lang().'</p>';

                105  

                106 ?>

Last edited by masonbarge; Jun 13th, 2006 at 16:16.
Reply With Quote
  #5 (permalink)  
Old Jun 14th, 2006, 10:31
Junior Member
Join Date: Apr 2006
Age: 27
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Re: PHP welcome message in viewer's language ???

Quote:
Originally Posted by masonbarge
You can certainly use php to detect a user's language. Here's one idea from PHParadise that looks to me like it should still work:

Code: Select all
001 <?php

                002 

                003 function    lixlpixel_get_env_var($Var)

                004 {

                005     if(empty($GLOBALS[$Var]))

                006     {

                007         $GLOBALS[$Var]=(!empty($GLOBALS['_SERVER'][$Var]))?

                008         $GLOBALS['_SERVER'][$Var]:

                009         (!empty($GLOBALS['HTTP_SERVER_VARS'][$Var]))?

                010         $GLOBALS['HTTP_SERVER_VARS'][$Var]:'';

                011     }

                012 }

                013  

                014 function    lixlpixel_detect_lang()

                015 {

                016     //    Detect    HTTP_ACCEPT_LANGUAGE    &    HTTP_USER_AGENT.

                017     lixlpixel_get_env_var('HTTP_ACCEPT_LANGUAGE');

                018     lixlpixel_get_env_var('HTTP_USER_AGENT');

                019     

                020     $_AL=strtolower($GLOBALS['HTTP_ACCEPT_LANGUAGE']);

                021     $_UA=strtolower($GLOBALS['HTTP_USER_AGENT']);

                022     

                023     //    Try    to    detect    Primary    language    if    several    languages    are    accepted.

                024     foreach($GLOBALS['_LANG']    as    $K)

                025     {

                026         if(strpos($_AL,    $K)===0)

                027             return    $K;

                028     }

                029     

                030     //    Try    to    detect    any    language    if    not    yet    detected.

                031     foreach($GLOBALS['_LANG']    as    $K)

                032     {

                033         if(strpos($_AL,    $K)!==false)

                034             return    $K;

                035     }

                036     foreach($GLOBALS['_LANG']    as    $K)

                037     {

                038         if(preg_match("/[\[\(    ]{$K}[;,_\-\)]/",$_UA))

                039             return    $K;

                040     }

                041     

                042     //    Return    default    language    if    language    is    not    yet    detected.

                043     return    $GLOBALS['_DLANG'];

                044 }

                045  

                046 //    Define    default    language.

                047 $GLOBALS['_DLANG']='en';

                048  

                049 //    Define    all    available    languages.

                050 //    WARNING:    uncomment    all    available    languages

                051 

                052 $GLOBALS['_LANG']    =    array(

                053         'af',    //    afrikaans.

                054         'ar',    //    arabic.

                055         'bg',    //    bulgarian.

                056         'ca',    //    catalan.

                057         'cs',    //    czech.

                058         'da',    //    danish.

                059         'de',    //    german.

                060         'el',    //    greek.

                061         'en',    //    english.

                062         'es',    //    spanish.

                063         'et',    //    estonian.

                064         'fi',    //    finnish.

                065         'fr',    //    french.

                066         'gl',    //    galician.

                067         'he',    //    hebrew.

                068         'hi',    //    hindi.

                069         'hr',    //    croatian.

                070         'hu',    //    hungarian.

                071         'id',    //    indonesian.

                072         'it',    //    italian.

                073         'ja',    //    japanese.

                074         'ko',    //    korean.

                075         'ka',    //    georgian.

                076         'lt',    //    lithuanian.

                077         'lv',    //    latvian.

                078         'ms',    //    malay.

                079         'nl',    //    dutch.

                080         'no',    //    norwegian.

                081         'pl',    //    polish.

                082         'pt',    //    portuguese.

                083         'ro',    //    romanian.

                084         'ru',    //    russian.

                085         'sk',    //    slovak.

                086         'sl',    //    slovenian.

                087         'sq',    //    albanian.

                088         'sr',    //    serbian.

                089         'sv',    //    swedish.

                090         'th',    //    thai.

                091         'tr',    //    turkish.

                092         'uk',    //    ukrainian.

                093         'zh'    //    chinese.

                094 );

                095  

                096 //    Redirect    to    the    correct    location.

                097 

                098 //    Example    Implementations

                099 

                100 //    Redirect    to    the    correct    location.

                101 //header('location:    http://www.your_site.com/index_'.lixlpixel_detect_lang().'.php');

                102 

                103 //    simply    display    the    detected    language

                104 echo    '<p>the    language    detected    is:    '.lixlpixel_detect_lang().'</p>';

                105  

                106 ?>
Thanks for your time & help. Much appreciated.

However, wouldn't you say this code is to IDENTIFIES viewer's language & then REDIRECT them to somewhere else, while in my case, the whole website in itself is in English, but it's ONLY one single message at the top that I wish to make it appear in their own language such as if the user's language is French, it should say, "Bonjour, hope you enjoy your stay (in French, course).

I've edited & added the following using the IF....ELSE statement:
PHP: Select all

// Redirect to the correct location.

//header('location: http://www.your_site.com/index_'.lixlpixel_detect_lang().'.php'); // Example Implementation

if ($GLOBALS['_LANG'] = 'en') {
echo 
'<span class="colorTextRed">"Hello"';

else if (
$GLOBALS['_LANG'] = 'fr') {
echo 
'<span class="colorTextRed">"Bonjour"';
}
else {
echo 
'<span class="colorTextRed">"Hello"';
}

//echo '<span class="colorTextRed">The Language detected is: '.lixlpixel_detect_lang(); // For Demonstration
?> 

?> 
Problem is EVEN if I change my browser lanauge to French, I STILL get the "Hello" message, rather than "Bonjour". Am I doing something utterly wrong/silly ???

By the way, could you enlighten me little further as HOW EXACTLY the language gets detected. Where does the script get the information ??? Some people around mentioned the user of word "header". What would that be ???

I'll in the mean time, try to ask people speaking these languages or use some online translation service to translate this English sentences "Hello, hope you enjoy your stay".

Last edited by j4mes_bond25; Jun 14th, 2006 at 11:57.
Reply With Quote
Reply

Tags
php, welcome, message, viewers, language

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use this language? alexgeek Other Programming Languages 35 Sep 20th, 2007 21:10
Creative Language Resources nativejam Free Web Site Critique 12 Mar 2nd, 2007 11:51
language for website ycpc55 PHP Forum 11 Jan 15th, 2007 09:39
Language Conversion jpvsd Other Programming Languages 0 Jun 15th, 2006 17:42
Is ASP the ideal Language? RVFmal Classic ASP 3 Jun 30th, 2005 08:51


All times are GMT. The time now is 08:28.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43