language detection script
CaptFlood
Status: New User - Welcome
Joined: 01 Feb 2007
Posts: 2
Location: UK
Reply Quote
Hi Guys
I've been trying to use the Language Detection script and I can't seem to get it to work at all.
For the print out i've been using
include 'language_detection.php';

$lang = get_languages($feature) and
$lang = get_languages($feature[1]) and
$lang = get_languages($user_languages) and
$lang = get_languages($user_languages[1])

All seem to return nothing.
I am using the full browser detection script which works perfect, also the cookie detection script, just can't get the hang of the language script. What am i doing wrong?
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
As it says in the beginning of the script:

:: Quote ::
this will return an array composed of a 4 item array for each language the os supports
1. full language abbreviation, like en-ca
2. primary language, like en
3. full language string, like English (Canada)
4. primary language string, like English

The function returns this array.

So you're not reading the script right. the $feature variable is what you want the script to do, not the return directions. If $feature == 'data', then it returns the array, if $feature == 'header' then it redirects.

You're right though to ask, in the years that script has been up nobody has actually noticed that the top basic instructions don't list these two possible values for $feature.

:: Code ::
include 'language_detection.php';

$lang = get_languages('data');

will return an array contained in $lang, which you can then use, like:

:: Code ::
echo 'your browser language is set to ' . $lang[2];

I'll have to add a note about that in script comment header
Back to top
language script
CaptFlood
Status: New User - Welcome
Joined: 01 Feb 2007
Posts: 2
Location: UK
Reply Quote
Hi Guys
Thanks for a quick reply, however i still can't get it to work.
I take your point about not reading it properly though, I went down the wrong route entirely, that's what i get for moving to fast.

Anyway i tried your suggestion:
include 'language_detection.php';
$lang = get_languages('data');

echo "<tr><td class='n'>0 ".$lang[0]."</td></tr>\n";
echo "<tr><td class='n'>1 ".$lang[1]."</td></tr>\n";
echo "<tr><td class='n'>2 ".$lang[2]."</td></tr>\n";
echo "<tr><td class='n'>3 ".$lang[3]."</td></tr>\n";

and the results where (actual display):
0 Array // where 0 is $lang[0] and so on
1 Array
2
3

so it's back to the drawing board.

It took me about an hour but i've found the answer.
$lang = get_languages('data');
echo "<tr><td class='n'>".$lang[0][2]."</td></tr>\n";

Note the extra index [0][2] for $lang
this then shows:
English (United Kingdom)

echo "<tr><td class='n'>".$lang[1][2]."</td></tr>\n";
this shows:
English



Thanks for your help....
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Yes, it's been too long, haven't implemented that script in years.

That's right, it will be, for each language returned:

$lang[0][0-3]
$lang[1][0-3]

Forgot that it supported multiple languages.

When in doubt, always use print_r($lang) to see what you actually have.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours