Given an array of objects (greetings) containing enumerated name-value pairs:
const greetings = []
greetings.EN = {
HELLO: 'Hello',
BYE: 'Goodbye',
SCRAM: 'Get lost'
}
greetings.ES = {
HELLO: 'Hola',
BYE: 'Asta luega',
SCRAM: 'Vete'
}
greetings.FR = {
HELLO: 'Bonjour',
BYE: 'Au revoir',
SCRAM: 'Allez-vous en'
}
The only way I can access an item is i.e.
console.log(greetings.EN.BYE)
Which can be implemented in 3 switch statements, one per language type see codepen
Rather than 3 switch statements, I would prefer use access an item with a syntax like :
let language = 'EN'
console.log(greetings.language.BYE)
which would allow me to directly access the translations without having to use the switch statements However, this produces a compiler error. Is there a way to resolve these values at run time?