app = Flask() CORS(app) Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger( name ) Initialize translator translator = Translator()
jawi_text = "سلامت datang کأ لومبور" result = translator.translate_jawi_to_rumi(jawi_text) google translate jawi kepada rumi
async function googleTranslate(text, sourceLang, targetLang) { // Using Google Translate API via a proxy service const url = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${sourceLang}&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}`; const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); // Parse the response let translation = ''; for (let i = 0; i < data[0].length; i++) { if (data[0][i][0]) { translation += data[0][i][0]; } } return translation; } app = Flask() CORS(app) Configure logging logging
def convert(self, jawi_text): """ Convert Jawi text to Rumi """ if not jawi_text: return "" result = [] i = 0 text_length = len(jawi_text) while i < text_length: # Check for special cases first (like 'لا') if i + 1 < text_length and jawi_text[i:i+2] == 'لا': result.append('la') i += 2 continue char = jawi_text[i] # Handle spaces and punctuation if char.isspace(): result.append(char) i += 1 continue # Convert character if char in self.jawi_to_rumi: converted = self.jawi_to_rumi[char] result.append(converted) else: # Keep unknown characters as-is result.append(char) i += 1 # Join and clean up rumi_text = ''.join(result) # Apply additional rules rumi_text = self._apply_rules(rumi_text) return rumi_text.strip() const response = await fetch(url)
.error { color: #f5576c; text-align: center; margin-top: 10px; display: none; }
// Add event listener for character count document.getElementById('inputText').addEventListener('input', updateCharCount); // Optional: Auto-translate as user types (with debounce) let timeoutId; document.getElementById('inputText').addEventListener('input', function() { updateCharCount(); clearTimeout(timeoutId); timeoutId = setTimeout(() => { if (this.value.trim()) { translateText(); } }, 1000); // Wait 1 second after user stops typing });