@echo off
setlocal
for %%I in ("%~dp0..") do set "PROJECT_DIR=%%~fI"
cd /d "%PROJECT_DIR%"

set "PYTHON_CMD="

if exist ".venv\Scripts\python.exe" (
  ".venv\Scripts\python.exe" --version >nul 2>&1
  if not errorlevel 1 (
    set "PYTHON_CMD=.venv\Scripts\python.exe"
  )
)

if not defined PYTHON_CMD (
  py -3.11 --version >nul 2>&1
  if not errorlevel 1 (
    set "PYTHON_CMD=py -3.11"
  )
)

if not defined PYTHON_CMD (
  py --version >nul 2>&1
  if not errorlevel 1 (
    set "PYTHON_CMD=py"
  )
)

if not defined PYTHON_CMD (
  python --version >nul 2>&1
  if not errorlevel 1 (
    set "PYTHON_CMD=python"
  )
)

if not defined PYTHON_CMD (
  echo Could not find a working Python interpreter.
  echo Please install Python 3.11+ or recreate .venv.
  exit /b 1
)

%PYTHON_CMD% sync_language_files.py
if errorlevel 1 (
  echo Language sync failed.
  exit /b 1
)

echo Language sync finished.
