BIAF-offASR / frontend /src /components /TextTranslationTab.jsx
froster02's picture
feat: add multilingual UI (EN/HI/MR) with language toggle
994e42f
import { useLang } from '../LanguageContext';
export default function TextTranslationTab({
textInput, setTextInput,
textOutput,
textSrcLang, setTextSrcLang,
textTgtLang, setTextTgtLang,
detectedTextLang,
isTranslatingText, handleTextTranslate,
ttsAudioUrl,
isGeneratingTts, handleTextToSpeech,
}) {
const { t } = useLang();
return (
<div className="glass-card">
<div className="translator-grid" style={{ marginBottom: '1.5rem' }}>
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">{t('text.srcLang')}</label>
<select className="select-control" value={textSrcLang} onChange={(e) => setTextSrcLang(e.target.value)}>
<option value="auto">โœจ {t('text.auto')}</option>
<option value="English">๐Ÿ‡ฌ๐Ÿ‡ง {t('text.english')}</option>
<option value="Hindi">๐Ÿ‡ฎ๐Ÿ‡ณ {t('text.hindi')}</option>
<option value="Marathi">๐Ÿ‡ฎ๐Ÿ‡ณ {t('text.marathi')}</option>
</select>
{detectedTextLang && (
<div style={{ fontSize: '0.75rem', color: 'var(--green-dark)', marginTop: '0.25rem', fontWeight: 600 }}>
โœจ {t('text.detected')}: {detectedTextLang}
</div>
)}
</div>
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">{t('text.tgtLang')}</label>
<select className="select-control" value={textTgtLang} onChange={(e) => setTextTgtLang(e.target.value)}>
<option value="Hindi">๐Ÿ‡ฎ๐Ÿ‡ณ {t('text.hindi')}</option>
<option value="Marathi">๐Ÿ‡ฎ๐Ÿ‡ณ {t('text.marathi')}</option>
<option value="English">๐Ÿ‡ฌ๐Ÿ‡ง {t('text.english')}</option>
</select>
</div>
</div>
<div className="translator-grid" style={{ marginBottom: '1.5rem' }}>
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">{t('text.input')}</label>
<textarea
className="textarea-control"
placeholder={t('text.inputPlaceholder')}
value={textInput}
onChange={(e) => setTextInput(e.target.value)}
/>
</div>
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">{t('text.output')}</label>
<div className="textarea-control output-box" style={{ cursor: 'default' }}>
{textOutput
? textOutput
: <span className="output-box-placeholder">{t('text.outputPlaceholder')}</span>
}
</div>
</div>
</div>
<div style={{ display: 'flex', gap: '1rem', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap' }}>
<button
className="btn btn-primary"
onClick={handleTextTranslate}
disabled={isTranslatingText || !textInput.trim()}
>
{isTranslatingText ? `โณ ${t('text.translating')}` : `โšก ${t('text.translate')}`}
</button>
{textOutput && (
<div style={{ display: 'flex', gap: '0.75rem', alignItems: 'center', flexWrap: 'wrap' }}>
<button
className="btn btn-secondary"
onClick={() => { navigator.clipboard.writeText(textOutput); alert('Copied!'); }}
>
๐Ÿ“‹ {t('text.copy')}
</button>
<button
className="btn btn-secondary"
onClick={handleTextToSpeech}
disabled={isGeneratingTts}
>
{isGeneratingTts ? `โณ ${t('text.ttsGenerating')}` : `๐Ÿ”Š ${t('text.tts')}`}
</button>
{ttsAudioUrl && (
<audio src={ttsAudioUrl} controls autoPlay className="custom-audio-player" style={{ width: '220px', marginTop: 0 }} />
)}
</div>
)}
</div>
</div>
);
}