#!/usr/bin/env bash
set -e

LOCALE=$1
# Lookup language code
LANGUAGE_CODE=`language-code "$LOCALE"`

# The directory where we store the built files
dist_dir="dist/$VERSION/$LANGUAGE_CODE"

# Register path to HTML ZIP download (we'll build it later)
export HTML_DOWNLOAD="spongedocs-$VERSION-$LANGUAGE_CODE.zip"

# Build HTML docs
echo "Building page for $LANGUAGE_CODE..."
sphinx-build -q -D "language=$LOCALE" -d "build/$LOCALE/doctrees" source "$dist_dir"

echo "Building ZIP for $LANGUAGE_CODE..."
cd "$dist_dir"
zip -9 -q -r "$HTML_DOWNLOAD" .
