add person info to NP block display

This commit is contained in:
lingdocs 2022-06-13 13:37:10 -04:00
parent 7eb5ad9560
commit 0a652ba6b8
3 changed files with 22 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "2.9.1", "version": "2.9.2",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -3,6 +3,7 @@ import classNames from "classnames";
import { import {
getEnglishFromRendered, getEnglishFromRendered,
} from "../../lib/phrase-building/np-tools"; } from "../../lib/phrase-building/np-tools";
import { getEnglishPersonInfo } from "../../library";
function Block({ opts, block }: { function Block({ opts, block }: {
opts: T.TextOptions, opts: T.TextOptions,
@ -219,7 +220,13 @@ export function NPBlock({ opts, children, inside, english }: {
<Adjectives opts={opts}>{np.selection.adjectives}</Adjectives> <Adjectives opts={opts}>{np.selection.adjectives}</Adjectives>
<div> {np.selection.ps[0].f}</div> <div> {np.selection.ps[0].f}</div>
</div> </div>
<div className={inside ? "small" : ""}>NP</div> <div className={inside ? "small" : ""}>
NP
{!inside ? <>
{` `}
<span className="text-muted small">({getEnglishPersonInfo(np.selection.person, "short")})</span>
</> : <></>}
</div>
<EnglishBelow>{english}</EnglishBelow> <EnglishBelow>{english}</EnglishBelow>
</div> </div>
} }

View File

@ -147,15 +147,20 @@ export function personIsPlural(person: T.Person): boolean {
return person > 5; return person > 5;
} }
export function getEnglishPersonInfo(person: T.Person): string { export function getEnglishPersonInfo(person: T.Person, version?: "short" | "long"): string {
const p = [0,1,6,7].includes(person) const p = ([0,1,6,7].includes(person)
? "1st pers" ? "1st"
: [2,3,8,9].includes(person) : [2,3,8,9].includes(person)
? "2nd pers" ? "2nd"
: "3rd pers"; : "3rd") + (version !== "short" ? " pers." : "");
const a = personIsPlural(person) ? "plur" : "sing"; const number = personIsPlural(person) ? "plur" : "sing";
const g = personGender(person); const n = version === "short"
return `${p}. ${a}. ${g}.`; ? (number === "plur" ? "pl" : "sn") : number;
const gender = personGender(person);
const g = version === "short"
? (gender === "masc" ? "m" : "f")
: gender;
return `${p} ${n}. ${g}.`;
} }
export function randomNumber(minInclusive: number, maxExclusive: number): number { export function randomNumber(minInclusive: number, maxExclusive: number): number {