Welcome to WebmasterWorld Guest from 54.224.230.193

Forum Moderators: open

Message Too Old, No Replies

Substructures and detecting if in structure and its values

     
4:01 am on Oct 7, 2012 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:226
votes: 1


I'm trying to create structure of various words and phrases in different languages. JavaScript isn't my strong suite, but something like:

var languages = {
"en":{
"load":"Loading",
"next":"Next",
"prev":"Previous"},
es:{
"load":"Carga",
"next":"Próximo",
"prev":"Anterior"},
pt:{
"load":"Carregamento",
"next":"Próximo",
"prev":"Anterior"}};

From this, or whatever may be a more appropriate structure, what I need to do is to be able to detect if a language is in the structure and what a given word or phrase is.

language.indexOf("en");
language.indexOf("de");

selectedLang = "es";
language.selectedLang.load;
language.selectedLang.next;

I'm not sure how best to persue this and would appreciate any advice. Thanks.
6:54 am on Oct 7, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


example

if ( languages[selectedLang] !== undefined ) { // have language
loadString = languages[selectedLang].load;
}
12:52 pm on Oct 7, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4988
votes: 12


You might consider using the YUI Internationalization utility for this.
[yuilibrary.com...]
1:17 am on Oct 8, 2012 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:226
votes: 1


Thanks Dave, that was exactly what I needed.

Fotiman, I'll look into that.