Files
imgPub/src/utils/translationUtils.js

26 lines
692 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
};