Türkçe çeviri özelliği eklendi (GLM 4.6 ile çeviri yapılıyor)
This commit is contained in:
25
src/utils/translationUtils.js
Normal file
25
src/utils/translationUtils.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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();
|
||||
};
|
||||
Reference in New Issue
Block a user