Files
2025-11-11 16:58:03 +01:00

2.9 KiB

Implementation Plan

  • 1. Add translate_title method to Ollama client

    • Create the translate_title() method in news_crawler/ollama_client.py that accepts a title string and target language parameter
    • Implement the translation prompt that instructs the model to translate German headlines to English without explanations
    • Configure Ollama API call with temperature=0.3 and num_predict=100 for consistent title-length translations
    • Implement response cleaning logic to remove quotes, extract first line only, and trim whitespace
    • Add error handling for timeout, connection errors, HTTP errors, and empty title input
    • Return a dictionary with success status, translated_title, error message, and duration fields
    • Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 4.1, 4.2, 4.3, 4.4, 4.5
  • 2. Integrate translation into crawler service

    • 2.1 Add translation call in crawl_rss_feed function

      • Locate the article processing section in news_crawler/crawler_service.py after content extraction
      • Store the original title from article_data or entry
      • Add conditional check for Config.OLLAMA_ENABLED before calling translation
      • Call ollama_client.translate_title() with the original title
      • Store the translation_result for later use in article document
      • Requirements: 1.1, 2.1
    • 2.2 Add console logging for translation status

      • Add "🌐 Translating title..." message before translation call
      • Add success message with duration: "✓ Title translated (X.Xs)"
      • Add failure message with error: "⚠ Translation failed: {error}"
      • Requirements: 5.1, 5.2, 5.3
    • 2.3 Update article document structure

      • Modify the article_doc dictionary to include title_en field with translated title or None
      • Add translated_at field set to datetime.utcnow() on success or None on failure
      • Ensure the original title field still contains the German title
      • Requirements: 1.2, 3.5
  • 3. Update newsletter template for bilingual title display

    • Modify news_sender/newsletter_template.html to display English title as primary heading when available
    • Add conditional logic to show original German title as subtitle only when English translation exists and differs
    • Style the subtitle with smaller font (13px), gray color (#999999), and italic formatting
    • Ensure fallback to German title when title_en is NULL or missing
    • Requirements: 1.3, 1.4, 1.5
  • 4. Test the translation feature end-to-end

    • Rebuild the crawler Docker container with the new translation code
    • Clear existing articles from the database for clean testing
    • Trigger a test crawl with max_articles=2 to process fresh articles
    • Verify console output shows translation status messages
    • Check MongoDB to confirm title_en and translated_at fields are populated
    • Send a test newsletter email to verify English titles display correctly with German subtitles
    • Requirements: 1.1, 1.2, 1.3, 1.4, 5.1, 5.2, 5.4, 5.5