#!/usr/bin/env python3
import requests
import re

MYANMAR_RE = re.compile(r'[\u1000-\u109F]')
TRANG_RE = re.compile(r'^\s*\[?\s*TRANG\s+\d+\s*\]?\s*$', re.IGNORECASE)

def is_myanmar(line):
    return bool(MYANMAR_RE.search(line))

def is_trang(line):
    return bool(TRANG_RE.match(line.strip()))

def translate_myanmar_to_vietnamese(text):
    url = "https://api.mymemory.translated.net/get"
    params = {'q': text, 'langpair': 'my|vi'}
    resp = requests.get(url, params=params, timeout=30)
    data = resp.json()
    if 'responseData' in data and 'translatedText' in data['responseData']:
        return data['responseData']['translatedText']
    return text

with open('Tam Bao Myn.txt', 'r', encoding='utf-8') as f:
    for i in range(20):
        line = f.readline()
        if not line:
            break
        stripped = line.rstrip('\n')
        print(f"Line {i+1}: {repr(stripped[:50])}")
        if not stripped:
            print("  (blank)")
        elif is_trang(stripped):
            print("  (TRANG)")
        elif is_myanmar(stripped):
            print("  (Myanmar)")
            trans = translate_myanmar_to_vietnamese(stripped)
            print(f"  → {trans}")
        else:
            print("  (other)")
        print()