Skip to content

Instantly share code, notes, and snippets.

@jpsc
Created December 3, 2021 14:43
Show Gist options
  • Save jpsc/26a73ce007a1b5129dbfcab81e59f029 to your computer and use it in GitHub Desktop.
Save jpsc/26a73ce007a1b5129dbfcab81e59f029 to your computer and use it in GitHub Desktop.
// // i18n is an object with the translations for that locale
// const i18n = {
// personal: {
// gender: {
// { male: 'Male' },
// //etc
// }
// },
// }
export translation(i18n, key) {
return i18n[key];
}
export getGender(gender) {
return translation(i18n, 'gender', gender);
}
export getNameWithGender(personalData){
return `${getGender(personalData['gender']) personalData['firstName'] personalData['lastName']}`
}
// If you want to test if the name with the prefix greeting you can import getNameWithGender and tested without needing the component
import { getNameWithGender } from './data-separation.mjs'
const data = {
gender: 'Female',
firstName: 'Claudia',
lastName: 'Hemling'
}
assert(getNameWithGender(data)).equals(' Mrs Claudia Hemling');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment