iksnae / actual-intelligence

A practical, non-technical guide to using AI tools like ChatGPT in everyday life
MIT License
0 stars 0 forks source link

Fix for Spanish Book Generation with Docker Container #49

Closed khaos-codi closed 3 months ago

khaos-codi commented 3 months ago

Spanish Book Generation Issue Analysis

I've analyzed the current issue with the Spanish book generation and found that while the PR #47 tried to address this, there are still issues with how the Docker container is handling the Spanish content. Here's a comprehensive fix:

Root Causes Identified:

  1. Resource Path Issues: The Spanish resource paths aren't consistently handled across all conversion tools
  2. Language-specific Metadata: The metadata for Spanish books needs explicit language tags in all conversion steps
  3. Docker Container Configuration: The book-builder container may need additional configuration for multilingual support
  4. File Copying Logic: The file copying in the build script needs to be more explicit about maintaining the Spanish files

Proposed Fixes:

  1. Update the generate-epub.sh script to explicitly handle language codes:
# In tools/scripts/generate-epub.sh, modify the container's generate-epub command:

# Add language as first-class parameter
generate-epub \
  --title "$BOOK_TITLE" \
  --author "Open Source Community" \
  --publisher "Khaos Studios" \
  --language "$LANGUAGE" \
  --resource-path "$RESOURCE_PATHS" \
  --verbose \
  "$INPUT_FILE" "$OUTPUT_FILE"
  1. Modify build-language.sh to ensure proper file staging for non-English versions:
# In tools/scripts/build-language.sh, add explicit copy operations:

# At the end of the script, add:
if [ "$LANGUAGE" != "en" ]; then
  echo "Ensuring $LANGUAGE files are copied to root build directory for release..."

  # Make sure files exist before copying
  if [ -f "$PDF_PATH" ]; then
    echo "Copying $PDF_PATH to build/$PDF_FILENAME"
    cp "$PDF_PATH" "build/$PDF_FILENAME"
  else
    echo "⚠️ Warning: $PDF_PATH does not exist, cannot copy to root build directory"
  fi

  if [ -f "$EPUB_PATH" ]; then
    echo "Copying $EPUB_PATH to build/$EPUB_FILENAME"
    cp "$EPUB_PATH" "build/$EPUB_FILENAME"
  else
    echo "⚠️ Warning: $EPUB_PATH does not exist, cannot copy to root build directory"
  fi

  if [ -f "$MOBI_PATH" ]; then
    echo "Copying $MOBI_PATH to build/$MOBI_FILENAME"
    cp "$MOBI_PATH" "build/$MOBI_FILENAME"
  else
    echo "⚠️ Warning: $MOBI_PATH does not exist, cannot copy to root build directory"
  fi

  if [ -f "$HTML_PATH" ]; then
    echo "Copying $HTML_PATH to build/$HTML_FILENAME"
    cp "$HTML_PATH" "build/$HTML_FILENAME"
  else
    echo "⚠️ Warning: $HTML_PATH does not exist, cannot copy to root build directory"
  fi
fi
  1. Add explicit verification in the GitHub workflow for Spanish files:
# In .github/workflows/build-book.yml, add a verification step:

- name: Verify Spanish build outputs
  run: |
    echo "=== Verifying Spanish Files ==="
    if [ -f "build/inteligencia-real.pdf" ]; then
      echo "✅ Spanish PDF exists"
      du -h build/inteligencia-real.pdf
    else
      echo "❌ Spanish PDF missing"
    fi

    if [ -f "build/inteligencia-real.epub" ]; then
      echo "✅ Spanish EPUB exists"
      du -h build/inteligencia-real.epub
    else
      echo "❌ Spanish EPUB missing"
    fi

    if [ -f "build/inteligencia-real.mobi" ]; then
      echo "✅ Spanish MOBI exists"
      du -h build/inteligencia-real.mobi
    else
      echo "❌ Spanish MOBI missing"
    fi

    echo "=== Checking Language-Specific Directories ==="
    find build -type d -name "es" | xargs ls -la
  1. Enhance Docker book-builder image to better support localization:
# Add to book-builder Dockerfile:
# Install additional localization packages
RUN apt-get update && apt-get install -y \
    locales \
    language-pack-es \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Generate all locales
RUN locale-gen en_US.UTF-8
RUN locale-gen es_ES.UTF-8

Testing Steps:

  1. Implement these changes in a new branch
  2. Verify both English and Spanish books build correctly
  3. Ensure files are copied to the appropriate locations
  4. Validate the release workflow includes both language versions

This approach should ensure that:

  1. All language-specific resources are properly handled
  2. Files are explicitly copied where they need to be
  3. The build system has better verification and error reporting
  4. The Docker container is properly configured for multilingual support

Let me know if you'd like me to implement this fix in a PR.