Skip to content

Commit

Permalink
add ps language tag
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Dec 18, 2023
1 parent c9f369d commit c6b4d19
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 80 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pashto-inflector",
"version": "7.0.3",
"version": "7.0.4",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "7.0.3",
"version": "7.0.4",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
100 changes: 59 additions & 41 deletions src/components/src/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,66 @@ import * as T from "../../types";

type PsStringWSub = T.PsString & { sub?: any };

function EnglishContent({ children }: { children: (string | JSX.Element)[] | (string | JSX.Element) }) {
if (Array.isArray(children)) {
return <>
{children.map((x) => <EnglishContent>{x}</EnglishContent>)}
</>
}
return <div className="text-muted">
{children}
</div>;
}

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

function Examples(
props: (
| {
ex: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[];
}
| {
children: T.PsJSX | T.PsJSX[] | PsStringWSub | PsStringWSub[];
}
) & {
opts: T.TextOptions;
lineHeight?: 0 | 1 | 2 | 3 | 4;
}
) {
const examples = "children" in props ? props.children : props.ex;
const Example = ({ children: text }: { children: PsStringWSub }) => (
<div
className={
props.lineHeight !== undefined ? `mb-${props.lineHeight}` : `mt-1 mb-3`
}
>
<div>
<Pashto opts={props.opts}>{text}</Pashto>
</div>
<div>
<Phonetics opts={props.opts}>{text}</Phonetics>
</div>
{text.e && <EnglishContent>{text.e}</EnglishContent>}
{text.sub && <div className="small text-muted">{text.sub}</div>}
</div>
);
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;
59 changes: 27 additions & 32 deletions src/components/src/Pashto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,37 @@
*
*/

import {
convertSpelling,
} from "../../lib/src/convert-spelling";
import {
phoneticsToDiacritics
} from "../../lib/src/phonetics-to-diacritics";
import { convertSpelling } from "../../lib/src/convert-spelling";
import { phoneticsToDiacritics } from "../../lib/src/phonetics-to-diacritics";
import { psJSXMap } from "./jsx-map";
import * as T from "../../types";

const Pashto = ({ opts, children: text }: {
opts: T.TextOptions,
children: T.PsString | T.PsJSX,
const Pashto = ({
opts,
children: text,
}: {
opts: T.TextOptions;
children: T.PsString | T.PsJSX;
}) => {
function convertText(ps: T.PsString, opts: T.TextOptions): string {
const p = opts.diacritics
? (phoneticsToDiacritics(ps.p, ps.f) || ps.p)
: ps.p;
return convertSpelling(p, opts.spelling);
}
const style = opts.pTextSize === "normal"
? undefined
: { fontSize: opts.pTextSize === "larger" ? "large" : "larger" };
return (
<span className="p-text" dir="rtl" style={style}>
{(typeof text.p !== "string" && typeof text.f !== "string")
?
psJSXMap(
text as T.PsJSX,
"p",
(ps: T.PsString) => convertText(ps, opts),
)
:
convertText(text as T.PsString, opts)
}
</span>
);
function convertText(ps: T.PsString, opts: T.TextOptions): string {
const p = opts.diacritics
? phoneticsToDiacritics(ps.p, ps.f) || ps.p
: ps.p;
return convertSpelling(p, opts.spelling);
}
const style =
opts.pTextSize === "normal"
? undefined
: { fontSize: opts.pTextSize === "larger" ? "large" : "larger" };
return (
<span className="p-text" dir="rtl" style={style} lang="ps">
{typeof text.p !== "string" && typeof text.f !== "string"
? psJSXMap(text as T.PsJSX, "p", (ps: T.PsString) =>
convertText(ps, opts)
)
: convertText(text as T.PsString, opts)}
</span>
);
};

export default Pashto;
2 changes: 1 addition & 1 deletion src/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/inflect",
"version": "7.0.3",
"version": "7.0.4",
"description": "Pashto inflector library",
"main": "dist/index.js",
"types": "dist/lib/library.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/src/misc-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ export function parseEc(ec: string): T.EnglishVerbConjugationEc {
if (s === "be") {
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])) {
const b = s.slice(0, -1);
return [`${s}`, `${b}ies`, `${s}ing`, `${b}ied`, `${b}ied`];
Expand Down

0 comments on commit c6b4d19

Please sign in to comment.