#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PY="$ROOT/scripts/.venv-i18n/bin/python"
LOG="/tmp/fix-en-leaks.log"
LOCALES=(th tl fil fr es it pl ja zh)

: >"$LOG"
echo "[$(date -Iseconds)] start" | tee -a "$LOG"

for loc in "${LOCALES[@]}"; do
  echo "[$(date -Iseconds)] === $loc ===" | tee -a "$LOG"
  PYTHONUNBUFFERED=1 "$PY" -u "$ROOT/scripts/fix-en-leaks.py" "$loc" --delay 0.15 2>&1 | tee -a "$LOG" || {
    echo "[$(date -Iseconds)] FAILED $loc" | tee -a "$LOG"
    exit 1
  }
done

echo "[$(date -Iseconds)] ALL DONE" | tee -a "$LOG"
