// Every Greek and Hebrew word in the study with its transliteration, so a
// speaker can rehearse them. Reached from the Script and Export stages.
import { useState } from 'react';
import { useApp } from '../context/AppContext.js';
import StudioShell from '../components/study/StudioShell.jsx';
import { buildPronunciationGuide } from '../utils/bibleUtils.jsx';
import { speakOriginalWord } from '../utils/wordStudy.js';
export default function PronunciationPage() {
const { project, setCurrentPage } = useApp();
const [search, setSearch] = useState('');
const [copied, setCopied] = useState(false);
const chapters = Array.isArray(project?.chapters) ? project.chapters : [];
// Collect all words with chapter context, deduplicated by Strong's number
const seen = new Set();
const entries = [];
chapters.forEach((ch) => {
ch.chunks.forEach((chunk) => {
(chunk.greekWords ?? []).forEach((word) => {
if (!word.lexeme && !word.transliteration) return;
const key = word.strongNumber || `${word.lexeme}__${word.transliteration}`;
if (seen.has(key)) return;
seen.add(key);
entries.push({ word, chapterRef: `${ch.book} ${ch.chapter}` });
});
});
});
const q = search.trim().toLowerCase();
const filtered = q
? entries.filter(({ word }) => [word.englishGloss, word.shortDefinition, word.lexeme, word.transliteration, word.strongNumber]
.some((f) => (f ?? '').toLowerCase().includes(q)))
: entries;
const greek = filtered.filter(({ word }) => !word.strongNumber?.startsWith('H'));
const hebrew = filtered.filter(({ word }) => word.strongNumber?.startsWith('H'));
const copyAll = () => {
navigator.clipboard.writeText(buildPronunciationGuide(project)).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
});
};
const btn = 'rounded-xl border border-[var(--r-line)] px-4 py-2 text-sm hover:bg-black/5';
return (
Pronunciation Guide
{project?.title &&
{project.title}
}
{entries.length} unique word{entries.length !== 1 ? 's' : ''} across all chapters
setSearch(e.target.value)}
className="mb-6 w-full rounded-xl border border-[var(--r-line)] bg-[var(--r-bar)] px-4 py-2.5 text-sm text-[var(--r-text)] placeholder:text-[var(--r-sub)] focus:outline-none focus:ring-2 focus:ring-[var(--r-line)]" />
{entries.length === 0 ? (
No words yet
Add Greek or Hebrew words in the Word study tab of the Study stage.
) : filtered.length === 0 ? (
No words match “{search}”
) : (
{greek.length > 0 && }
{hebrew.length > 0 && }
)}
);
}
function WordGroup({ title, words, onSpeak }) {
return (
{title} · {words.length} word{words.length !== 1 ? 's' : ''}
{words.map(({ word, chapterRef }) => )}
);
}
function WordCard({ word, chapterRef, onSpeak }) {
return (
{word.lexeme &&
{word.lexeme}
}
{word.transliteration &&
{word.transliteration}
}
{word.lexeme && }
{word.strongNumber && {word.strongNumber}}
{word.englishGloss &&
{word.englishGloss}
}
{word.shortDefinition && word.shortDefinition !== word.englishGloss &&
{word.shortDefinition}
}
{word.partOfSpeech && {word.partOfSpeech}}
{chapterRef}
);
}