Sandaysoft

Support forum for Cumulus weather station software
It is currently Thu May 23, 2013 3:02 pm
Please click here before posting. Help me to help you!
Useful Links: Cumulus FAQ • Enhancement requests • Wiki (documentation)
Please put your approximate location into your profile
Add your web site to the Cumulus user map
Vantage Pro2 users with firmware 3.00 should upgrade to fw 3.12 and Cumulus 1.9.4

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Browser language detection
PostPosted: Fri May 18, 2012 9:23 pm 
Offline
User avatar

Joined: Wed Jun 11, 2008 7:36 pm
Posts: 378
Location: L'Estartit, Spain
Weather Station: WMR-968
Operating System: Windows 8
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

_________________
Image


Top
 Profile  
 
 Post subject: Re: Browser language detection
PostPosted: Sun May 20, 2012 5:09 pm 
Offline
User avatar

Joined: Wed Sep 17, 2008 1:34 pm
Posts: 629
Location: Mesa, AZ USA
Weather Station: Davis VP2 Plus w/24 FARS
Operating System: WinX Pro SP3 Dedicated wstn
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):

Code:
// 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 );

_________________
Kevin
Image
All you need is Time, Aptitude and Desire ... and you can build just about anything...
Cumulus User Maps


Top
 Profile  
 
 Post subject: Re: Browser language detection
PostPosted: Sun May 20, 2012 9:35 pm 
Offline
User avatar

Joined: Wed Jun 11, 2008 7:36 pm
Posts: 378
Location: L'Estartit, Spain
Weather Station: WMR-968
Operating System: Windows 8
Quote:
Seems to work for me...


Thanks for the code tip!

Anyone out there with a native language other than English?

gwheelo

http://www.wheelocknet.net/cam/index_code_1.htm

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group