473,770 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting user language and branching

Hello,

I am a beginner. My website has 2 pages: one in English and one in
French. I would like non English people to be directed to the English
page. There I would like to display a particular sentence in 1 of 3
languages depending on the language of the visitor (this sentence would
be in Spanish or Italian or German and the rest of the page in English).

I have found this code to detect the language:

<SCRIPT language="javas cript">
<!--
function getlanguage(){
language=naviga tor.language;
if(language)
{language=langu age.substring(0 ,2);}
}
switch (language){
case "en" :
window.location ="english.ht m";
break;
case "fr" :
window.location ="french.htm ";
break;
default :
window.location ="english.ht m";
}

}
// -->
</SCRIPT>

But then I do not know if this code is standards compliant and what to
do in the English page to display the sentence in one of the 3 languages...

Can you please help me.

Thank you.
Mar 26 '07 #1
1 1539
On 26 Mar, 13:57, mouton <nos...@nospam. comwrote:
Hello,

I am a beginner. My website has 2 pages: one in English and one in
French. I would like non English people to be directed to the English
page. There I would like to display a particular sentence in 1 of 3
languages depending on the language of the visitor (this sentence would
be in Spanish or Italian or German and the rest of the page in English).

I have found this code to detect the language:

<SCRIPT language="javas cript">
<!--
function getlanguage(){
language=naviga tor.language;
if(language)
{language=langu age.substring(0 ,2);}}

switch (language){
case "en" :
window.location ="english.ht m";
break;
case "fr" :
window.location ="french.htm ";
break;
default :
window.location ="english.ht m";

}
}

// -->
</SCRIPT>

But then I do not know if this code is standards compliant and what to
do in the English page to display the sentence in one of the 3 languages...

Can you please help me.

Thank you.
do you have any control over your server at all - this is best done
server side. Do you have access use a scripting language like php?

server - apache: use Multiviews, saving your pages as dodah.html.en,
dodah.html.fr and .es
scripting - php: use the value of $_SERVER['HTTP_USER_AGEN T'] and look
through it to find the one at the start of the comma separated list.
Use that to return the strings you need within the doc sending
header( 'Content-Language: ' . $lang );
where $lang is en, fr or es and your script

the better way is to either use rewrites on apache and have you
content appear to the user to come from http://server.com/lang/path/to/file
or since your site is small, actually separate your content.

if you use scripting the best way is to use a session to persist the
browsers choice and use that to send appropriate content, setting the
right lang attributes in your xhtml if needed as well. Also dont
forget to allow the user to override the setting, use a cookie in
apache setting prefered-lang or with a post to a script in php which
overrides the session preferred lang

Mar 26 '07 #2

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

Similar topics

1
3329
by: Rookie | last post by:
I have done a lot of programming some time ago using Fortran and various varieties of the Basic programming languages, Hewlett Packard Technical Basic, QBasic, Quick Basic. With each of these languages there were documents (books, etc) which categorized and explained all of the functions, statements, etc. and how to use them. The documents explained the logic of the statement or function and provided examples. Also most of the books...
4
2267
by: Hal | last post by:
Can someone please tell me what is wrong with this script? <script language="JavaScript"> <!-- function HF_CloseAllChildren() { if (g_win1) != undefined { if ((g_win1) && !(g_win1.closed)) g_win1.close(); } }
1
3413
by: Mark Szlazak | last post by:
Is there a way to detect if an textarea onscroll event is working in Firefox (or Mozilla). I know that there is an onscroll event bubbling bug with current vesions of these browsers so I want to detect this problem with a test like "if (textarea.onscroll == 'undefined' || !textarea.onscroll) {}." Any help would be appreciated.
5
1550
by: guischarf | last post by:
I have the following code on files "a.php" and "b.php" ----------------------------- FILE a.php ----------------------------- <form action="a.php" method="post"> <input type="hidden" name="active" value="1"> <input type="submit" name="Submit" value="Send"> </form>
134
8045
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've increasingly been using scripting languages (especially Python and Bourne shell) which offer the same speed and yet are far more simple and safe to use. I can no longer understand why anyone would willingly use C to program anything but the lowest...
79
3794
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the relevant name owner? If I make a whisky and call it "Jack Daniels", I most probably will have some serious legal problems. "Mozilla" partially appeared because NCSA stopped them from using "Mosaic" in the UA string. Is it some different...
6
1684
by: Rex | last post by:
Hi all, If I want to detect a user's language, so that I can change some text to suit them, how do I do that in Javascript? Or aren't modern browsers supposed to be able to cope with more than one language on a page, separated somehow by language identifiers, and display only the appropriate text? Maybe
3
7600
by: Sems | last post by:
Hi I'm using the Session_End event in the global.asax to detect if a users sessions has ended. Is there any way to tell if the session end is due to it being expired and not abandoned? I'm trying to show the user a popup if their session has expired due to a timeout. Whats the best way to do this?
2
2407
pbmods
by: pbmods | last post by:
While researching SCM software, I came across Git . It looked phenomenal, especially the part about branching. Or at least, the way I thought it handled branching looked phenomenal. I'm curious if anyone out there is familiar enough with Git to shed some light on this issue: At first, I got really excited because I thought Git was moving my files around behind the scenes so that I could maintain different versions of my filesystem, but...
0
9618
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
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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
9906
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...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
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.