import json
import re
import sys
from pathlib import Path
import subprocess

sys.stdout.reconfigure(encoding='utf-8')

root = Path(r"c:\Projects\FreeExile")
catalog_file = root / "client" / "webapp" / "js" / "data" / "i18n_catalog.js"
escaped_path = str(catalog_file).replace("\\", "/")

node_script = """
const fs = require('fs');
const code = fs.readFileSync('""" + escaped_path + """', 'utf-8');
const fakeWindow = {};
const fn = new Function('window', code + '; return I18N_CATALOG;');
const catalog = fn(fakeWindow);
console.log(JSON.stringify(catalog));
"""

res = subprocess.run(["node", "-e", node_script], capture_output=True, encoding="utf-8", check=True)
catalog = json.loads(res.stdout)

vi_dict = catalog.get("vi", {})
en_dict = catalog.get("en", {})

desc_keys = [k for k in vi_dict.keys() if k.endswith("_desc")]
print(f"Total description keys in VI: {len(desc_keys)}")

for k in sorted(desc_keys):
    vi_val = vi_dict.get(k, "")
    en_val = en_dict.get(k, "")
    print(f"\n--- KEY: {k} ---")
    print(f"VI ({len(vi_val)} chars, {len(vi_val.split())} words): {vi_val}")
    print(f"EN ({len(en_val)} chars, {len(en_val.split())} words): {en_val}")
