Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Language localization in Javacript
- Date: Wed, 28 Sep 2011 17:35:40 +0900
- From: Lewske Wada <ryu@example.com>
- Subject: Re: [tlug] Language localization in Javacript
- References: <CA+kCxRb8df237PV1ZdvOp5Emuqgz_=RdVzpa_fPMJEbQZRX3sA@example.com> <4E81AF97.2060001@example.com> <CA+kCxRaM==wbOGH4Qcs__qsPY9SEyQNH9OBefxDbHv0Y2MQ6YQ@example.com> <5E9006D3-F900-45BB-A4F7-5ECBCC045D4A@example.com>
On Sep 28, 2011, at 5:19 PM, Lewske Wada wrote: > On Sep 28, 2011, at 4:40 PM, Martin G wrote: >> How would I set up a conditional for three or more possible languages? >> I'm likely to have a dozen or more languages available for this >> application. > > Why don't you add more branches in the switch-case statement? > > switch (navigator.language.substr(0, 2)) { > case "en" : > document.writeln("Hello."); > break; > case "de" : > document.writeln("Guten Tag."); > break; > case "fr" : > document.writeln("Bonjour."); > break; > case "es" : > document.writeln("Hola!"); > break; > case "pt" : > document.writeln("Boa tarde."); > break; > case "ru" : > document.writeln("Здравствуйте!"); > break; > case "ja" : > document.writeln("こんにちは."); > break; > } For multi-platform (multi-browser) enhancement, you may want to create and use your own function like this : function getBrowserLanguage() { if (document.all) // for e4,e5,e6,o6,o7 return navigator.browserLanguage else if (document.layers) // for n4 return navigator.language else if (document.getElementById) // for n6,n7,m1,s1 return navigator.language.substr(0,2) } switch (getBrowserLanguage()) { ........ whatever goes on. Anyway it's always complicated when it comes to supporting different browsers. Cheers, Lewske Wada Web: http://run.sh/ Email: ryu@example.com Facebook: Lewske Wada Skype: lewske
- References:
- [tlug] Language localization in Javacript
- From: Martin G
- Re: [tlug] Language localization in Javacript
- From: Darren Cook
- Re: [tlug] Language localization in Javacript
- From: Martin G
- Re: [tlug] Language localization in Javacript
- From: Lewske Wada
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Language localization in Javacript
- Next by Date: Re: [tlug] Language localization in Javacript
- Previous by thread: Re: [tlug] Language localization in Javacript
- Next by thread: Re: [tlug] Language localization in Javacript
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links