Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active July 18, 2016 19:23
Show Gist options
  • Select an option

  • Save phynet/763098fbc2366f1c5a5bd48b1a574bf0 to your computer and use it in GitHub Desktop.

Select an option

Save phynet/763098fbc2366f1c5a5bd48b1a574bf0 to your computer and use it in GitHub Desktop.
How to create dynamic keys in JS...order by same keys
/*
Entry:
[ { key: 'activar_reserva_email',
ES: 'Email que usarás en la aplicación ',
EN: 'The email address you will use on the application' },
{ key: 'activar_reserva_cuenta_no_registrado',
ES: 'La cuenta donde quieres recibir los pagos',
EN: 'The account where you wish to receive your payments' },
{ key: 'activar_reserva_boton_no_registrado',
ES: 'Activar reserva online y publicar',
EN: 'Activate online booking service and publish it' },
{ key: 'activar_reserva_condiciones',
ES: 'Acepto las condiciones de uso de la Aplicación',
EN: 'I accept the conditions of usage' },
{ key: 'activar_reserva_boton_registrado',
ES: 'Vincular tu cuenta de con la aplicación',
EN: 'Link your account with application' } ]
Result:
{ ES:
{ activar_reserva_email: 'Email que usarás en la aplicación',
activar_reserva_cuenta_no_registrado: 'La cuenta donde quieres recibir los pagos',
activar_reserva_boton_no_registrado: 'Activar reserva online y publicar',
activar_reserva_condiciones: 'Acepto las condiciones de uso de la Aplicación',
activar_reserva_boton_registrado: 'Vincular tu cuenta de con la aplicación' },
EN:
{ activar_reserva_email_avaibook: 'The email address you will use on the application',
activar_reserva_cuenta_no_registrado: 'The account where you wish to receive your payments',
activar_reserva_boton_no_registrado: 'Activate online booking service and publish it',
activar_reserva_condiciones: 'I accept the conditions of usage',
activar_reserva_boton_registrado: 'Link your account with application' } }
*/
function iterateThroughLangs(rows){
var langValues = {};
if(rows){
for (var i = 0;i < Object.keys(rows).length; i++){
var entry = rows[i];
for (var key in entry){
if (key !== 'key'){
langValues[key] = langValues[key] || {};
langValues[key][entry['key']] = entry[key];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment