import React, { useState } from 'react'; import { Modal, View, Text, TextInput, Button, StyleSheet, TouchableOpacity, KeyboardAvoidingView, Platform, ScrollView } from 'react-native'; import { View as ThemedView } from './Themed'; import { FontAwesome } from '@expo/vector-icons'; import i18n from '@/i18n'; type TranslatorModalProps = { visible: boolean; onClose: () => void; }; const TranslatorModal = ({ visible, onClose }: TranslatorModalProps) => { const [turkmenText, setTurkmenText] = useState(''); const [arabicText, setArabicText] = useState(''); const handleTranslate = async () => { if (turkmenText.trim() === '') { setArabicText(''); return; } // --- 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 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(i18n.t("Error: Could not translate.")); } }; return ( {i18n.t('Translator')} Türkmençe Arapça {arabicText} {i18n.t('Translate')} ); }; const styles = StyleSheet.create({ keyboardAvoidingContainer: { flex: 1, width: '100%', }, centeredView: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0.5)', width: '100%', }, scrollViewContent: { flexGrow: 1, justifyContent: 'center', alignItems: 'center', width: '100%', }, modalView: { margin: 20, backgroundColor: 'white', borderRadius: 20, padding: 35, alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.25, shadowRadius: 4, elevation: 5, width: '100%', minWidth: '90%', }, closeButton: { position: 'absolute', top: 10, right: 10, }, modalTitle: { fontSize: 20, fontWeight: 'bold', marginBottom: 20, }, inputContainer: { marginBottom: 15, minWidth: '90%', }, label: { fontSize: 16, marginBottom: 5, color: '#333', }, textInput: { borderWidth: 1, borderColor: '#ddd', borderRadius: 10, padding: 10, fontSize: 16, minWidth: '90%', }, turkmenInput: { height: 100, textAlignVertical: 'top', }, arabicOutputContainer: { height: 100, borderWidth: 1, borderColor: '#ddd', borderRadius: 10, padding: 10, backgroundColor: '#f9f9f9', justifyContent: 'center', }, arabicText: { fontSize: 18, textAlign: 'right', // For RTL text }, translateButton: { marginTop: 15, }, translateButtonText: { color: '#D4AF37', fontSize: 18, fontWeight: '500', }, }); export default TranslatorModal;