I am playing around with a browser language detection scheme to automatically display in one of my offered languages: English, French, Dutch, German, Spanish, and Catalan.
English is the default and I know that works. I would appreciate anyone using one of the other five languages to give the test page a try with various browsers, IE, Firefox, Chrome, Opera...
Give it a whirl please and let me know how it works for you.
http://www.wheelocknet.net/cam/index_code_1.htm
Here is the javascript:
if ( window.navigator.language ) // Firefox and Opera
{
var lang_code = window.navigator.language;
}
else if ( navigator.browserLanguage ) // Internet Explorer, of course MS has to different
{
var lang_code = navigator.browserLanguage;
}
else // We don't know
{
var lang_code = null;
}
var posted_opt=lang_code.substring(0,2);
switch(posted_opt) {
case 'en' : posted_opt = "gb";break;
case 'fr' : posted_opt = "fr";break;
case 'nl' : posted_opt = "nl";break;
case 'de' : posted_opt = "de";break;
case 'es' : posted_opt = "es";break;
case 'ca' : posted_opt = "ct";break;
default : posted_opt = "gb";break;
}
select_lang(posted_opt );Thanks for your time.
All suggestions and corrections are very welcome.
Thanks for you time.
George Wheelock
http://www.wheelocknet.net/cumulus/gauges.html?gb
Welcome to the Cumulus Support forum.
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Browser language detection
Moderator: daj
-
TNETWeather
Re: Browser language detection
Seems to work for me... though I rarely use JavaScript.
I would have coded the logic a bit different to get away from the nested else's which get confusing (again, I am not a JavaScript programmer):
I would have coded the logic a bit different to get away from the nested else's which get confusing (again, I am not a JavaScript programmer):
Code: Select all
// Start out with Unknown
var lang_code = en;
// Firefox and Opera
if ( window.navigator.language ) {
var lang_code = window.navigator.language;
}
// Internet Explorer, of course MS has to different
if ( navigator.browserLanguage ) {
var lang_code = navigator.browserLanguage;
}
var posted_opt=lang_code.substring(0,2);
switch(posted_opt) {
case 'en' : posted_opt = "gb";break;
case 'fr' : posted_opt = "fr";break;
case 'nl' : posted_opt = "nl";break;
case 'de' : posted_opt = "de";break;
case 'es' : posted_opt = "es";break;
case 'ca' : posted_opt = "ct";break;
default : posted_opt = "gb";break;
}
select_lang(posted_opt );- gwheelo
- Posts: 453
- Joined: Wed 11 Jun 2008 7:36 pm
- Weather Station: WMR-88
- Operating System: Windows 8.1
- Location: L'Estartit, Spain
- Contact:
Re: Browser language detection
Thanks for the code tip!Seems to work for me...
Anyone out there with a native language other than English?
gwheelo
http://www.wheelocknet.net/cam/index_code_1.htm