oops got the search ability back in there

This commit is contained in:
lingdocs 2022-04-07 15:41:02 +05:00
parent 35a5c3d3a5
commit d0850066a2
1 changed files with 36 additions and 8 deletions

View File

@ -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: <InlinePs opts={opts}>
{{ p: e.entry.p, f: removeFVarients(e.entry.f), e: eng }}
</InlinePs>,
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: <InlinePs opts={opts}>
{{ p: entry.p, f: removeFVarients(entry.f), e: english }}
</InlinePs>,
label: `${ps.p} - ${ps.f} (${english})`,
value: entry.ts.toString(),
};
}