Mailing List Archive


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

Re: [tlug] Language localization in Javacript



The colon used here is the "ternary operator", a C-style shortcut to
mimic an if statement.
http://en.wikipedia.org/wiki/Ternary_operation
For multiple languages, you'd use a "switch" statement to set the
language first.

--Richard


2011/9/28 Martin G <ebisumartin@example.com>:
> Darren, (and Lewske),
>
> Thank you for responding.
>
>> var x=(language=="en"?english:japanese);
>> ...
>> alert(x.l00001);
>
> This works perfectly. If I understand it, it's essentially an if/else
> condition, so if language equals "en", then we use the English set,
> and if not, then we get Japanese.
>
> However, I've never used this syntax before and I'm having a hard time
> extending it. I looked up Javascript and colons on Google, but all I
> saw was how it's used in JSON syntax, which doesn't seem to be how
> it's used here.
>
> 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.
>
> Any advice is much appreciated.
>
> --
> Dave M G
>
> --
> To unsubscribe from this mailing list,
> please see the instructions at http://lists.tlug.jp/list.html
>
> The TLUG mailing list is hosted by the award-winning Internet provider
> ASAHI Net.
> Visit ASAHI Net's English-language Web page: http://asahi-net.jp/en/
>



-- 
--Richard Frankum


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links