diff --git a/src/components/np-picker/picker-tools.tsx b/src/components/np-picker/picker-tools.tsx index 9601918..c4e7b60 100644 --- a/src/components/np-picker/picker-tools.tsx +++ b/src/components/np-picker/picker-tools.tsx @@ -12,7 +12,9 @@ import { getEnglishWord, removeFVarients, Types as T, - InlinePs, + phoneticsToDiacritics, + convertSpelling, + translatePhonetics, } from "@lingdocs/pashto-inflector"; export const zIndexProps = { @@ -22,18 +24,42 @@ export const zIndexProps = { export function makeVerbSelectOption(e: VerbEntry, opts: T.TextOptions): { value: string, label: string | JSX.Element } { const eng = getEnglishVerb(e.entry); + const ps = plainTextPsAdjustment( + { p: e.entry.p, f: removeFVarients(e.entry.f) }, + opts, + ); return { - label: - {{ p: e.entry.p, f: removeFVarients(e.entry.f), e: eng }} - , + label: `${ps.p} - ${ps.f} (${eng})`, value: e.entry.ts.toString(), }; } +function plainTextPsAdjustment(ps: T.PsString, opts: T.TextOptions): T.PsString { + function getP(ps: T.PsString): string { + const p = opts.diacritics + ? (phoneticsToDiacritics(ps.p, ps.f) || ps.p) + : ps.p; + return convertSpelling(p, opts.spelling); + } + function getF(f: string): string { + if (opts.phonetics === "none") { + return ""; + } + return opts.phonetics === "lingdocs" + ? f + : translatePhonetics(f, { + dialect: opts.dialect, + // @ts-ignore - weird TS not picking up the elimination of "none herre" + system: opts.phonetics, + }); + } + return { p: getP(ps), f: getF(ps.f) }; +} + export function makeSelectOption( e: T.DictionaryEntry | VerbEntry | NounEntry | AdjectiveEntry | LocativeAdverbEntry, opts: T.TextOptions, -): { value: string, label: JSX.Element | string } { +): { value: string, label: string } { const entry = "entry" in e ? e.entry : e; const eng = (isVerbEntry(e)) ? (getEnglishParticiple(e.entry)) @@ -45,10 +71,12 @@ export function makeSelectOption( : ("singular" in eng && eng.singular !== undefined) ? eng.singular : eng.plural; + const ps = plainTextPsAdjustment( + { p: entry.p, f: removeFVarients(entry.f) }, + opts, + ); return { - label: - {{ p: entry.p, f: removeFVarients(entry.f), e: english }} - , + label: `${ps.p} - ${ps.f} (${english})`, value: entry.ts.toString(), }; }