Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Language localization in Javacript



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;
}

Cheers,
Lewske Wada
Web: http://run.sh/
Email: ryu@example.com
Facebook: Lewske Wada
Skype: lewske




Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links