From 213062bda4579a876c4e00772d704b57e42e575f Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Thu, 28 Aug 2025 16:10:52 +0500 Subject: [PATCH] WIP --- components/TranslatorModal.tsx | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/components/TranslatorModal.tsx b/components/TranslatorModal.tsx index ab9d98e..f1e98c1 100644 --- a/components/TranslatorModal.tsx +++ b/components/TranslatorModal.tsx @@ -19,18 +19,35 @@ const TranslatorModal = ({ visible, onClose }: TranslatorModalProps) => { return; } - // --- Placeholder for Translation API call --- - // You would replace this with your actual translation logic. - // For example, calling a function that makes an API request to a translation service. + // --- Replace this with your Google Cloud API Key --- + const API_KEY = 'YOUR_GOOGLE_CLOUD_API_KEY'; + const API_URL = `https://translation.googleapis.com/language/translate/v2?key=${API_KEY}`; + try { - // const translated = await translateText(turkmenText, 'tk', 'ar'); - // setArabicText(translated); - setArabicText(`(Translation for: ${turkmenText})`); // Mock response + const response = await fetch(API_URL, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + q: turkmenText, + source: 'tk', + target: 'ar', + format: 'text', + }), + }); + + const json = await response.json(); + + if (json.data && json.data.translations && json.data.translations.length > 0) { + setArabicText(json.data.translations[0].translatedText); + } else { + throw new Error('Invalid response from translation API'); + } } catch (error) { console.error("Translation error:", error); - setArabicText("Error: Could not translate."); + setArabicText(i18n.t("Error: Could not translate.")); } - // ----------------------------------------- }; return (