PDA

View Full Version : Identifying visitor's default language


dhtmlhelp
04-26-2003, 10:03 PM
Hi,

how can I identify the language of a user visiting my site. I will be using subdomains to redirect users to the section in their language, is there a simple way of doing this?

Also from site statistics it seems that many users have not defined a language in their settings, or retain this information. Is there a way of getting around this or should I simply have a condition saying if language none than go to etc.

thanks,

DH

Nightfire
04-26-2003, 11:58 PM
I think the best way is just having a link for the user to click on. For all you know, it could be someone who can't speak the native language connecting from a foreign PC, then he/she won't be able to understand your site.

example:

Man from UK, goes to saudi arabia internet centre, connects to your site and see's nothing but arabic language everywhere. How is he meant to know what your site says?

dhtmlhelp
04-27-2003, 12:43 AM
Hi Nightfire,

thanks but I don't think many of my users will be english men accessing the site from saudi arabia. I thought about your solution (I will have links for different languages as well) but since my audience speaks 5 different languages which language should I start with? So while I would be pleasing the englishman in the middle east, 4/5 of the other users would be unhappy.

Is there a solution to the problem?

DH

EDIT: I want to avoid at all costs a splash page where to choose the language. Also I would like every page on the site to be dynamic.

Example: site.com/dir/article.php?artno=23

If I type that in the browser I should be redirected to uk.site.com/dir/article.php?artno=23

and if I am french (and if my broswer says so) I should be redirected to fr.site.com/dir/article.php?artno=23

Is there a way of achieving this?

Also, the article might not be available in french. In this case can I get the page to dynamically state (for example): This article is not available in french but you can view the english version by clicking here.

DH

scroots
04-27-2003, 09:45 AM
on either the 1st page or on every page on a subdomain but the other countires/nationalites flags near the top right which link to the repsective sub domain.

that way wherever they enter they have a hope of using the site in the correct language of there choice.


scroots

mordred
04-27-2003, 12:50 PM
To automatically detect the language the browser has set, look at the value in

$_SERVER["HTTP_ACCEPT_LANGUAGE"]

But being able to later switch languages through text links or flag images is very user friendly IMHO.

dhtmlhelp
04-27-2003, 05:39 PM
Hi Mordred,

thanks, just what I needed. Regarding my last question I suppose you would need to see the code but I post the question here anyway just in case there is an answer.

If for example an article is not available in a specific language, let's say french, but I am still redirected (in this case as a french user) to that article page (in french), is there an easy way to say (aside from 'sorry, this article is not available in french')

'You can click here for the english version of this article' (or whatever language that article is available in).

DH

mordred
04-27-2003, 06:44 PM
Well yes there is, but it seems quite simple to me so I fear I haven't understood the problem.

Pseudo-code:

if (!isFrenchArticleAvailable($id)) {
print 'Cet article ne pas la';
print 'Tu peut lire l'article en anglais';
print "<a href='us.site.com/index.php?articleId=$id'>cliquer</a>";
} else {
// print french article
}

dhtmlhelp
04-28-2003, 12:56 AM
Hi mordred,

indeed, what is the ! , is that for php with posgresql or standard php?

thank,

DH

EDIT: In reply to your message below I can onl say silly me. I had seen it before but never really realised its convenience, thanks.

mordred
04-28-2003, 10:16 PM
"!" is the unary operator that negates a logical expression. In this case, it has the same effect as writing

if (isFrenchArticleAvailable($id) == false)

see
http://www.php.net/manual/en/language.operators.logical.php