#!/usr/bin/env bash
# Sequentieller Deep-Fill – eine Locale nach der anderen, mit Fortschritts-Log.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PY="$ROOT/scripts/.venv-i18n/bin/python"
LOG="${TMPDIR:-/tmp}/i18n-deep-fill.log"
# Nur noch offene Locales (fr/es/it bereits gefüllt)
LOCALES=(pl ja zh th tl fil)

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

for loc in "${LOCALES[@]}"; do
  echo "[$(date -Iseconds)] === $loc ===" | tee -a "$LOG"
  if ! PYTHONUNBUFFERED=1 "$PY" -u "$ROOT/scripts/fill-i18n-deep.py" --locale "$loc" --delay 0.2 2>&1 | tee -a "$LOG"; then
    echo "[$(date -Iseconds)] FAILED $loc" | tee -a "$LOG"
    exit 1
  fi
done

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