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",
"version": "2.9.1",
"version": "2.9.2",
"author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com",

View File

@ -3,6 +3,7 @@ import classNames from "classnames";
import {
getEnglishFromRendered,
} from "../../lib/phrase-building/np-tools";
import { getEnglishPersonInfo } from "../../library";
function Block({ opts, block }: {
opts: T.TextOptions,
@ -219,7 +220,13 @@ export function NPBlock({ opts, children, inside, english }: {
<Adjectives opts={opts}>{np.selection.adjectives}</Adjectives>
<div> {np.selection.ps[0].f}</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>
</div>
}

View File

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