From cb1b56f5a0eddbf77446f415f2beda57c8305f85 Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
Date: Sun, 23 Nov 2025 01:12:53 +0700
Subject: wut

---
 packages/prosody-ui/src/LangText.tsx | 78 ++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 packages/prosody-ui/src/LangText.tsx

(limited to 'packages/prosody-ui/src/LangText.tsx')

diff --git a/packages/prosody-ui/src/LangText.tsx b/packages/prosody-ui/src/LangText.tsx
new file mode 100644
index 0000000..790c499
--- /dev/null
+++ b/packages/prosody-ui/src/LangText.tsx
@@ -0,0 +1,78 @@
+import { franc } from "franc-all";
+import React, { useEffect, useState } from "react";
+import ThaiText from "./thai/ThaiText";
+import { ColoredText } from "./components/Sentence";
+import type { AnalyzeRes, WordData } from "./logic/types";
+import { detectScript, scriptFromLang } from "./logic/utils";
+import LatinText from "./latin/LatinText";
+import { buildWiktionaryURL, parseWiktionary } from "./logic/wiki";
+import type { Result } from "sortug";
+
+export default function LangText({
+  text,
+  lang,
+  theme,
+  fetchWiki,
+  handleWord,
+}: {
+  text: string;
+  lang?: string;
+  theme?: string;
+  fetchWiki?: (url: string) => Promise<string>;
+  handleWord?: (wd: Result<WordData>) => any;
+}) {
+  const [llang, setLang] = useState("");
+  const [script, setScript] = useState(scriptFromLang(lang || "", text));
+  useEffect(() => {
+    if (!lang) {
+      const res = franc(text);
+      setLang(res);
+    } else setLang(lang);
+  }, [text]);
+  console.log("langtext", { text, llang, script });
+
+  async function openWord(word: string) {
+    // console.log("looking up", word);
+    // const url = buildWiktionaryURL(word);
+    // const html = await fetchWiki(url);
+    // const parsed = parseWiktionary(html, url);
+    // console.log({ parsed });
+    // if ("error" in parsed) handleWord(parsed);
+    // else {
+    //   const wd: WordData = {
+    //     spelling: word,
+    //     lang: llang,
+    //     ipa: parsed.ok.ipa[0],
+    //     meanings: parsed.ok.meanings,
+    //     references: { url: parsed.ok.url },
+    //   };
+    //   handleWord({ ok: wd });
+    // }
+    // // const d = data[s];
+    // // setModal(d);
+    // // setModal(<WordModal data={d} lang={lang} />);
+  }
+
+  return (
+    <div className="lang-text-container">
+      {script === "Thai" ? (
+        <ThaiText text={text} openWord={openWord} />
+      ) : script === "Latin" ? (
+        <LatinText text={text} lang={llang} openWord={openWord} />
+      ) : (
+        <Generic text={text} lang={llang} />
+      )}
+    </div>
+  );
+}
+function Generic({ text, lang }: { text: string; lang: string }) {
+  const [data, setData] = useState<AnalyzeRes>();
+  useEffect(() => {
+    // segmentate(text, lang)
+  }, [text, lang]);
+  console.log({ lang }, "generic");
+  // <p className="lang-lang">{lang}</p>
+  // <p className="lang-text">{text}</p>
+  // {data && <ColoredText frags={Object.keys(data)} />}
+  return <div className="lang-text-div"></div>;
+}
-- 
cgit v1.2.3

