#!/bin/bash

# Script de compilation des traductions pour Vigilus Nettoyage
# Ce script compile les fichiers .po en .mo pour le multilingue

echo "========================================="
echo "  COMPILATION DES TRADUCTIONS"
echo "========================================="
echo ""

# Vérifier si gettext est installé
if ! command -v msgfmt &> /dev/null
then
    echo "⚠️  GNU gettext n'est pas installé !"
    echo ""
    echo "Installation requise :"
    echo ""
    echo "Sur Ubuntu/Debian :"
    echo "  sudo apt-get install gettext"
    echo ""
    echo "Sur macOS :"
    echo "  brew install gettext"
    echo "  brew link gettext --force"
    echo ""
    echo "Sur Windows :"
    echo "  Téléchargez depuis : https://mlocati.github.io/articles/gettext-iconv-windows.html"
    echo ""
    exit 1
fi

echo "✅ gettext est installé"
echo ""

# Compiler les traductions
echo "📦 Compilation des traductions..."
python manage.py compilemessages

if [ $? -eq 0 ]; then
    echo ""
    echo "✅ TRADUCTIONS COMPILÉES AVEC SUCCÈS !"
    echo ""
    echo "Les fichiers .mo ont été créés dans locale/en/LC_MESSAGES/"
    echo ""
    echo "Prochaines étapes :"
    echo "1. Redémarrez le serveur Django"
    echo "2. Testez le site en anglais : http://localhost:8000/en/"
    echo "3. Utilisez le sélecteur de langue dans le menu"
    echo ""
else
    echo ""
    echo "❌ Erreur lors de la compilation"
    echo ""
    echo "Vérifiez que :"
    echo "1. Le fichier locale/en/LC_MESSAGES/django.po existe"
    echo "2. Le format du fichier .po est correct"
    echo ""
fi

echo "========================================="
