import copy import re import time import xml.etree.ElementTree as ET from pathlib import Path import requests ROOT = Path(__file__).resolve().parent.parent RES = ROOT / "app" / "src" / "main" / "res" SOURCE = RES / "values" / "strings.xml" API = "http://127.0.0.1:5000/translate" LANGUAGES = { "Brazilian Portuguese": ("pt", "values-pt-rBR"), "Spanish": ("es", "values-es"), "Simplified Chinese": ("zh", "values-zh-rCN"), "Japanese": ("ja", "values-ja"), } PLACEHOLDER = re.compile( r"%(?:\d+\$)?[-#+ 0,(<]*\d*(?:\.\d+)?[a-zA-Z%]" ) def sanitize_for_android_xml(text): if not text: return text # Clean up stray backslashes that are not valid Android escapes (n, t, ', ", \\, @, ?, u) def clean_slash(match): nxt = match.group(1) if nxt in ("n", "t", "'", '"', "\\", "@", "?", "u"): return "\\" + nxt return nxt text = re.sub(r'\\(.)', clean_slash, text) # Ensure unescaped single quotes are escaped with \' # Match single quotes not preceded by backslash text = re.sub(r"(?