add ps language tag

This commit is contained in:
adueck 2023-12-18 13:59:57 +04:00
parent c9f369de09
commit c6b4d19abf
8 changed files with 96 additions and 80 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.0.3", "version": "7.0.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.0.3", "version": "7.0.4",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.0.3", "version": "7.0.4",
"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

@ -1,12 +1,12 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.0.3", "version": "7.0.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.0.3", "version": "7.0.4",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@formkit/auto-animate": "^1.0.0-beta.3", "@formkit/auto-animate": "^1.0.0-beta.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.0.3", "version": "7.0.4",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -12,48 +12,66 @@ import * as T from "../../types";
type PsStringWSub = T.PsString & { sub?: any }; type PsStringWSub = T.PsString & { sub?: any };
function EnglishContent({ children }: { children: (string | JSX.Element)[] | (string | JSX.Element) }) { function EnglishContent({
if (Array.isArray(children)) { children,
return <> }: {
{children.map((x) => <EnglishContent>{x}</EnglishContent>)} children: (string | JSX.Element)[] | (string | JSX.Element);
</> }) {
} if (Array.isArray(children)) {
return <div className="text-muted"> return (
{children} <>
</div>; {children.map((x) => (
<EnglishContent>{x}</EnglishContent>
))}
</>
);
}
return (
<div className="text-muted" lang="en">
{children}
</div>
);
} }
function Examples(props: ({ function Examples(
ex: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[], props: (
} | { | {
children: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[], ex: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[];
}) & { }
opts: T.TextOptions, | {
lineHeight?: 0 | 1 | 2 | 3 | 4, children: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[];
}) { }
const examples = "children" in props ? props.children : props.ex; ) & {
const Example = ({ children: text }: { children: PsStringWSub }) => ( opts: T.TextOptions;
<div className={props.lineHeight !== undefined ? `mb-${props.lineHeight}` : `mt-1 mb-3`}> lineHeight?: 0 | 1 | 2 | 3 | 4;
<div> }
<Pashto opts={props.opts}>{text}</Pashto> ) {
</div> const examples = "children" in props ? props.children : props.ex;
<div> const Example = ({ children: text }: { children: PsStringWSub }) => (
<Phonetics opts={props.opts}>{text}</Phonetics> <div
</div> className={
{text.e && <EnglishContent> props.lineHeight !== undefined ? `mb-${props.lineHeight}` : `mt-1 mb-3`
{text.e} }
</EnglishContent>} >
{text.sub && <div className="small text-muted"> <div>
{text.sub} <Pashto opts={props.opts}>{text}</Pashto>
</div>} </div>
</div> <div>
); <Phonetics opts={props.opts}>{text}</Phonetics>
return Array.isArray(examples) ? </div>
<div> {text.e && <EnglishContent>{text.e}</EnglishContent>}
{examples.map((example, i) => <Example key={i}>{example as PsStringWSub}</Example>)} {text.sub && <div className="small text-muted">{text.sub}</div>}
</div> </div>
: );
<Example>{examples as PsStringWSub}</Example>; return Array.isArray(examples) ? (
<div>
{examples.map((example, i) => (
<Example key={i}>{example as PsStringWSub}</Example>
))}
</div>
) : (
<Example>{examples as PsStringWSub}</Example>
);
} }
export default Examples; export default Examples;

View File

@ -6,42 +6,37 @@
* *
*/ */
import { import { convertSpelling } from "../../lib/src/convert-spelling";
convertSpelling, import { phoneticsToDiacritics } from "../../lib/src/phonetics-to-diacritics";
} from "../../lib/src/convert-spelling";
import {
phoneticsToDiacritics
} from "../../lib/src/phonetics-to-diacritics";
import { psJSXMap } from "./jsx-map"; import { psJSXMap } from "./jsx-map";
import * as T from "../../types"; import * as T from "../../types";
const Pashto = ({ opts, children: text }: { const Pashto = ({
opts: T.TextOptions, opts,
children: T.PsString | T.PsJSX, children: text,
}: {
opts: T.TextOptions;
children: T.PsString | T.PsJSX;
}) => { }) => {
function convertText(ps: T.PsString, opts: T.TextOptions): string { function convertText(ps: T.PsString, opts: T.TextOptions): string {
const p = opts.diacritics const p = opts.diacritics
? (phoneticsToDiacritics(ps.p, ps.f) || ps.p) ? phoneticsToDiacritics(ps.p, ps.f) || ps.p
: ps.p; : ps.p;
return convertSpelling(p, opts.spelling); return convertSpelling(p, opts.spelling);
} }
const style = opts.pTextSize === "normal" const style =
? undefined opts.pTextSize === "normal"
: { fontSize: opts.pTextSize === "larger" ? "large" : "larger" }; ? undefined
return ( : { fontSize: opts.pTextSize === "larger" ? "large" : "larger" };
<span className="p-text" dir="rtl" style={style}> return (
{(typeof text.p !== "string" && typeof text.f !== "string") <span className="p-text" dir="rtl" style={style} lang="ps">
? {typeof text.p !== "string" && typeof text.f !== "string"
psJSXMap( ? psJSXMap(text as T.PsJSX, "p", (ps: T.PsString) =>
text as T.PsJSX, convertText(ps, opts)
"p", )
(ps: T.PsString) => convertText(ps, opts), : convertText(text as T.PsString, opts)}
) </span>
: );
convertText(text as T.PsString, opts)
}
</span>
);
}; };
export default Pashto; export default Pashto;

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "7.0.3", "version": "7.0.4",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",

View File

@ -310,6 +310,9 @@ export function parseEc(ec: string): T.EnglishVerbConjugationEc {
if (s === "be") { if (s === "be") {
return ["am", "is", "being", "was", "been"]; return ["am", "is", "being", "was", "been"];
} }
if (s === "give") {
return ["give", "gives", "giving", "gave", "gave"];
}
if (s.slice(-1) === "y" && !isVowel(s.slice(-2)[0])) { if (s.slice(-1) === "y" && !isVowel(s.slice(-2)[0])) {
const b = s.slice(0, -1); const b = s.slice(0, -1);
return [`${s}`, `${b}ies`, `${s}ing`, `${b}ied`, `${b}ied`]; return [`${s}`, `${b}ies`, `${s}ing`, `${b}ied`, `${b}ied`];