Last active
September 6, 2021 19:06
-
-
Save etjossem/37efa7131504bb39f162f2c4841fa7d5 to your computer and use it in GitHub Desktop.
You can add pronoun support to your app, reusable across users and outputs through a simple template literal. Here's one way to do it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
P = function(person, theyConjugation) { | |
let conjugation = theyConjugation; | |
const allPronouns = { | |
"they/them": { | |
"subject": "they", | |
"object": "them", | |
"possessive-determiner": "their", | |
"possessive-pronoun": "theirs", | |
"reflexive": "themselves", | |
"be-present": "are", | |
"be-past": "were", | |
"be-present-contracted": "they're" | |
}, | |
"she/her": { | |
"subject": "she", | |
"object": "her", | |
"possessive-determiner": "her", | |
"possessive-pronoun": "hers", | |
"reflexive": "herself", | |
"be-present": "is", | |
"be-past": "was", | |
"be-present-contracted": "she's" | |
}, | |
"he/him": { | |
"subject": "he", | |
"object": "him", | |
"possessive-determiner": "his", | |
"possessive-pronoun": "his", | |
"reflexive": "himself", | |
"be-present": "is", | |
"be-past": "was", | |
"be-present-contracted": "he's" | |
} | |
}; | |
const isUpperCase = (conjugation.charAt(0) == conjugation.charAt(0).toUpperCase()) ? true : false; | |
if (isUpperCase) { conjugation = conjugation.toLowerCase() } | |
let conjugations = conjugation.split(" "); | |
const reCase = (s) => { if (isUpperCase) { return s.charAt(0).toUpperCase() + s.slice(1) } else {return s } } | |
const pronouns = person.pronouns ? allPronouns[person.pronouns] : allPronouns["they/them"]; | |
conjugations = conjugations.map(conjugation => { | |
switch (conjugation) { | |
case 'they': | |
return pronouns["subject"]; | |
case 'them': | |
return pronouns["object"]; | |
case 'their': | |
return pronouns["possessive-determiner"]; | |
case 'theirs': | |
return pronouns["possessive-pronoun"]; | |
case 'themselves': | |
return pronouns["reflexive"]; | |
case 'themself': | |
return pronouns["reflexive"]; | |
case 'are': | |
return pronouns["be-present"]; | |
case 'were': | |
return pronouns["be-past"]; | |
case "they're": | |
return pronouns["be-present-contracted"]; | |
default: | |
return conjugation; | |
} | |
}); | |
return reCase(conjugations.join(" ")); | |
} | |
// Usage: | |
// 1. Have a notion of a user or person. | |
// 2. Let a user select their pronouns from a dropdown provided by the keys of P.allPronouns | |
// 3. Use ${P(human, "They")} inside a `` string to conjugate the human's pronouns correctly! | |
let alex = { | |
uid: 1, | |
name: "Alex" | |
} | |
let carol = { | |
uid: 2, | |
name: "Carol" | |
} | |
let eric = { | |
uid: 3, | |
name: "Eric" | |
} | |
alex.pronouns = "they/them"; | |
carol.pronouns = "she/her"; | |
eric.pronouns = "he/him"; | |
const getTestPronounsParagraph = (s) => `${P(s, "They")} went to the park. | |
I went with ${P(s, "them")}. | |
${P(s, "They")} brought ${P(s, "their")} boomerang. | |
At least I think it was ${P(s, "theirs")}. | |
${P(s, "They")} threw the boomerang to ${P(s, "themselves")}. | |
${P(s, "They were")} in the park for hours. | |
I think ${P(s, "they're")} still out there!` | |
console.log(getTestPronounsParagraph(alex)); | |
console.log(getTestPronounsParagraph(carol)); | |
console.log(getTestPronounsParagraph(eric)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs:
"They went to the park.
I went with them.
They brought their boomerang.
At least I think it was theirs.
They threw the boomerang to themselves.
They were in the park for hours.
I think they're still out there!"
"She went to the park.
I went with her.
She brought her boomerang.
At least I think it was hers.
She threw the boomerang to herself.
She was in the park for hours.
I think she's still out there!"
"He went to the park.
I went with him.
He brought his boomerang.
At least I think it was his.
He threw the boomerang to himself.
He was in the park for hours.
I think he's still out there!"