26 lines
692 B
JavaScript
26 lines
692 B
JavaScript
const API_BASE = import.meta.env.VITE_API_BASE_URL || 'http://localhost:4000';
|
||
|
||
export const translateChunkToTurkish = async (text) => {
|
||
if (!text?.trim()) {
|
||
throw new Error('Çevrilecek metin bulunamadı.');
|
||
}
|
||
|
||
const response = await fetch(`${API_BASE}/translate`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ text }),
|
||
});
|
||
|
||
if (!response.ok) {
|
||
const message = await response.text();
|
||
throw new Error(message || 'Çeviri isteği başarısız oldu.');
|
||
}
|
||
|
||
const payload = await response.json();
|
||
if (!payload?.text) {
|
||
throw new Error('Çeviri yanıtı boş döndü.');
|
||
}
|
||
|
||
return payload.text.trim();
|
||
};
|