#!/usr/bin/env bash
set -euo pipefail

source ./scripts/Unix/starter.sh

if [ ! -f .env ]; then
  log_warning ".env file not found. Exiting without running Docker steps."
  exit 0
fi

# Check placeholders
log_step "Checking placeholders in PO files..."
if ! docker compose exec app uv run manage.py check_translated -l ALL -a ALL; then
  log_error "PO files have placeholder issues"
  exit 1
fi
log_success "PO files have no placeholder issues!"

# Compile messages
log_step "Compiling PO files into MO files..."
if ! docker compose exec app uv run manage.py compilemessages -l ar_AR -l cs_CZ -l da_DK -l de_DE -l en_GB -l en_US -l es_ES -l fa_IR -l fr_FR -l he_IL -l hi_IN -l hr_HR -l id_ID -l it_IT -l ja_JP -l kk_KZ -l ko_KR -l nl_NL -l no_NO -l pl_PL -l pt_BR -l ro_RO -l ru_RU -l sv_SE -l th_TH -l tr_TR -l vi_VN -l zh_Hans; then
  log_error "Failed to compile messages"
  exit 1
fi
log_success "Compiled successfully!"

echo
log_result "Translation compilation complete!"
