473,698 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check HTTP_ACCEPT_LAN GUAGE using Javascript?

It's quite easy in Php:

<?php

$language = $_SERVER['HTTP_ACCEPT_LA NGUAGE'];
$language_short = substr($taal,0, 2);

echo $language_short ;
?>
But would love to do it in Javascript..... .

Anybody?

Many thanks in advance!!
Edo.
Jul 20 '05 #1
8 14654

"Edo van der Zouwen" <ezouwen@haalwe g_removthis_and this_xs4all.nl> schreef
in bericht news:Xn******** *************** ******@216.168. 3.44...

But would love to do it in Javascript..... .

Anybody?


IE extends the navigator object with two properties you could reference:

navigator.syste mLanguage
navigator.userL anguage

Doesn't work in other browsers and I'm not shure whether this would work on
a mac or not...
JW

Jul 20 '05 #2
Janwillem Borleffs wrote:
"Edo van der Zouwen" <ezouwen@haalwe g_removthis_and this_xs4all.nl> schreef
in bericht news:Xn******** *************** ******@216.168. 3.44...
But would love to do it in Javascript..... .

Anybody?

IE extends the navigator object with two properties you could reference:

navigator.syste mLanguage
navigator.userL anguage

Doesn't work in other browsers and I'm not shure whether this would work on
a mac or not...


Gecko based browsers look like they use

navigator.langu age

My reference says this goes back to NN4.

.... this doesn't seem to give exactly what the ACCEPT_LANGUAGE header
would have, but it might be close enough ...

Regards,
Stephen

JW


Jul 20 '05 #3
Stephen <ss*****@austin .rr.com> wrote in
news:mR******** ***********@twi ster.austin.rr. com:
Janwillem Borleffs wrote:
"Edo van der Zouwen" <ezouwen@haalwe g_removthis_and this_xs4all.nl>
schreef in bericht
news:Xn******** *************** ******@216.168. 3.44...
But would love to do it in Javascript..... .

Anybody?

IE extends the navigator object with two properties you could
reference:

navigator.syste mLanguage
navigator.userL anguage

Doesn't work in other browsers and I'm not shure whether this would
work on a mac or not...


Gecko based browsers look like they use

navigator.langu age

My reference says this goes back to NN4.

... this doesn't seem to give exactly what the ACCEPT_LANGUAGE header
would have, but it might be close enough ...

Regards,
Stephen

JW


Thanks for both replies. However. the .userlanguage .browserlanguag e or
..systemlanguag e properties give the language of the browser or system.

In a browser, you can however also set the 'preferred language' in which
you can see a webpage.

For example, many people outside the US or UK have an english browser,
but would like to see webpages in their home language. This can not be
solved by using the properties above.

Any more ideas?

Thanks,
Edo.
P.S. By the way, for those interested, this is the code for checking the
browser language:

(example for dutch, polish and english users, which will be directed to
index_en.html, index_pl.html or index_nl.html)

<SCRIPT LANGUAGE="JavaS cript1.2"><!--
// The following only works in JavaScript 1.2 or greater:
function showpage(code) {

location = ("index_" + code + ".html");
}
if (navigator.appN ame == 'Netscape')
var language = navigator.langu age;
else
var language = navigator.brows erLanguage;

var code = language.substr ing(0,2);

if (code == 'pl' || code == 'nl' || code == 'en')
showpage(code);
else
showpage('en');
//--></SCRIPT>
Jul 20 '05 #4
Edo van der Zouwen wrote:

[...snip suggestions to use navigator.userL anguage, navigator.langu age, etc. ...]
Thanks for both replies. However. the .userlanguage .browserlanguag e or
.systemlanguage properties give the language of the browser or system.

In a browser, you can however also set the 'preferred language' in which
you can see a webpage.

For example, many people outside the US or UK have an english browser,
but would like to see webpages in their home language. This can not be
solved by using the properties above.

Any more ideas?

As far as I know, the HTTP request & headers sent with the request are
not accessible to javascript. This is probably (my guess) because these
are formed immediately before transmission and too late for server-side
scripting to make use of.

I believe I mentioned before, my prefered solution would be to use the
content-negotiation capabilities of HTTP 1.1 and configure the web
server to handle the content decision-making. How to do this is beyond
the scope of this NG, which is fortunate for me because it is presently
also beyond the scope of my knowledge. :-)

Sorry I've no further suggestions.
Stephen



P.S. By the way, for those interested, this is the code for checking the
browser language:

[...snip...]


Jul 20 '05 #5
Stephen <ss*****@austin .rr.com> wrote in
news:aN******** ***********@twi ster.austin.rr. com:

As far as I know, the HTTP request & headers sent with the request are
not accessible to javascript. This is probably (my guess) because
these are formed immediately before transmission and too late for
server-side scripting to make use of.

I believe I mentioned before, my prefered solution would be to use the
content-negotiation capabilities of HTTP 1.1 and configure the web
server to handle the content decision-making. How to do this is beyond
the scope of this NG, which is fortunate for me because it is
presently also beyond the scope of my knowledge. :-)

Sorry I've no further suggestions.
Stephen


Thanks for your input.

Cheers,
Edo.
Jul 20 '05 #6
I have found the following solution, which is a combination of php and
Javascript.

Look at how the variable from php is passed onto Javascript.

This code is based on the following input for the propertie:
http://www.weijers.net/sitemap.html

and the following for passing the variable:
http://www.sitepointforums.com/showt...hreadid=106385


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php

$preflanguage = $_SERVER['HTTP_ACCEPT_LA NGUAG E'];
#Check the property
$lang = substr($preflan guage,0,2);
#Take the first 2 characters

if ( $lang == "nl" or $lang == "en" or $lang =="pl")
{
$filename = "index_" . $lang . ".html";
#create the filename to go to later

}

else

{
$lang = "en";
$filename = "index_en.html" ;
#create the filename to go to later

}

?>

<SCRIPT LANGUAGE=JAVASC RIPT>
location = ("<?php echo $filename; ?>");
//Let javascript redirect, using the php variable

</script>
</body>
</html>

I'm sure it isn't the most beautiful solution, but it works!

Edo.
Jul 20 '05 #7
Edo van der Zouwen wrote:
Stephen <ss*****@austin .rr.com> wrote in
news:aN******** ***********@twi ster.austin.rr. com:
As far as I know, the HTTP request & headers sent with the request are
not accessible to javascript. This is probably (my guess) because
these are formed immediately before transmission and too late for
server-side scripting to make use of.
I saw your solution, but just to correct my misstatement here: I meant
"too late for *client*-side scripting to make use of" ...
S.

I believe I mentioned before, my prefered solution would be to use the
content-negotiation capabilities of HTTP 1.1 and configure the web
server to handle the content decision-making. How to do this is beyond
the scope of this NG, which is fortunate for me because it is
presently also beyond the scope of my knowledge. :-)

Sorry I've no further suggestions.
Stephen

Thanks for your input.

Cheers,
Edo.


Jul 20 '05 #8
Edo van der Zouwen wrote:
I have found the following solution, which is a combination of php and
Javascript.

Look at how the variable from php is passed onto Javascript.

This code is based on the following input for the propertie:
http://www.weijers.net/sitemap.html

and the following for passing the variable:
http://www.sitepointforums.com/showt...hreadid=106385
[...snip the code sample...]
I'm sure it isn't the most beautiful solution, but it works!


A very acceptable solution, here. Good digging.
This also prompts me to believe that using server-side includes you
could achieve the same thing:

<script type="text/javascript">
var acceptLang="<!--#echo var="HTTP_ACCEP T_LANGUAGE"-->"
// figure out which language by parsing "acceptLang "
switch(myLangua ge) {
case "nl":
...
break;
case "en":
...
break;
case "pl":
...
break;
default:
...
break;
}
// or something similar
</script>

Very like your PHP approach.

Stephen
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5317
by: BbT | last post by:
On my site I have a code based on $_SERVER, to selelect language variable: if(!isset($_SESSION)) { if(preg_match("/pl/i", $_SERVER)) { $_SESSION = "pl"; } elseif(preg_match("/en/i", $_SERVER)) { $_SESSION = "en"; } elseif(preg_match("/de/i", $_SERVER)) {
2
5480
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the photo size to 1 meg. I would like to check the file size in JavaScript on the page, instead of on the server. Anyone know how I can check the file size in JavaScript?
6
61599
by: Jim | last post by:
How do I check if javascript is enabled in PHP? TIA, Jim
44
10201
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
10
5203
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
19
107975
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular demand, I have added a section that also covers how to use a validator control to check if a text box...
2
5173
by: RvT | last post by:
I have an interesting problem. I have FireFox2, IE7 and Opera9 as test browsers. All browsers are in Dutch. When I execute the following: <?=$_SERVER?> The result is as follows: FireFox: nl,en-us;q=0.7,en;q=0.3 Opera: nl-NL,nl;q=0.9,en;q=0.8
11
2067
by: Patrick | last post by:
Trying this question again in a different way and expanding it to another newsgroup. Looking for how I would do this. For an html form; Say I have three check boxes A, B, and C . When I click on a checkbox a dropdown window will open next to it and the selections will be 1, 2, and 3. I want to use the same script and dropdown for each of the 3 check boxes and be able to return values independent of each other. Meaning if I check box A...
3
8265
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to Internet Explorer. I cannot check the file size on the web server because IIS throws the following...
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.