Skip to content

raphcss/CloudyTrad

Repository files navigation

CloudyTrad - Language Detection & Translation Service

CloudyTrad provides language detection and translation capabilities for CloudyAI using a hybrid approach combining multiple detection libraries and LibreTranslate for neural translation.

🎯 Features

  • Hybrid Language Detection: Combines LibreTranslate, LanguageDetect, and franc-min
  • Neural Translation: LibreTranslate for accurate translations
  • Optimized for Short Text: Special handling for single words/phrases
  • 50+ Languages: Supports major world languages
  • API Authentication: Token-based security

🚀 Quick Start

Installation

cd CloudyTrad
npm install

Docker Setup (LibreTranslate)

docker-compose up -d

This starts LibreTranslate on port 5000.

Configuration

Create .env file:

PORT=5001
API_TOKEN=your-secret-token-here
LIBRETRANSLATE_URL=http://localhost:5000
LIBRETRANSLATE_KEY=

Running

npm start

📡 API Endpoints

POST /detect

Detect language of text.

Headers:

Authorization: Bearer your-secret-token-here
Content-Type: application/json

Request:

{
  "q": "Bonjour le monde"
}

Response:

[
  {
    "language": "fr",
    "confidence": 0.95
  }
]

POST /translate

Translate text to target language.

Headers:

Authorization: Bearer your-secret-token-here
Content-Type: application/json

Request:

{
  "q": "Hello world",
  "target": "fr"
}

Response:

{
  "translatedText": "Bonjour le monde"
}

GET /health

Health check endpoint (no authentication required).

Response:

{
  "status": "healthy",
  "service": "CloudyTrad",
  "libreTranslate": "http://localhost:5000"
}

🔧 Technical Details

Detection Strategy

  1. LibreTranslate (Neural) - Primary detector for longer text
  2. LanguageDetect (N-gram) - Better for short text (<50 chars)
  3. franc-min (Statistical) - Fallback detector

Supported Languages

  • English (en)
  • French (fr)
  • Spanish (es)
  • German (de)
  • Italian (it)
  • Portuguese (pt)
  • And 40+ more...

See ISO_MAP in source code for full list.

🐳 Docker

LibreTranslate runs in Docker for neural translation:

version: '3'
services:
  libretranslate:
    image: libretranslate/libretranslate:latest
    ports:
      - "5000:5000"
    environment:
      - LT_LOAD_ONLY=en,fr,es,de

🔒 Security

All endpoints except /health require authentication:

curl -X POST http://localhost:5001/detect \
  -H "Authorization: Bearer your-secret-token-here" \
  -H "Content-Type: application/json" \
  -d '{"q":"Bonjour"}'

📝 Environment Variables

Variable Description Default
PORT Server port 5001
API_TOKEN Authentication token your-secret-token-here
LIBRETRANSLATE_URL LibreTranslate service URL http://localhost:5000
LIBRETRANSLATE_KEY LibreTranslate API key (if needed) ``

🔗 Integration

CloudyTrad is called by CloudyMod for language detection:

const response = await fetch('http://localhost:5001/detect', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-token',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ q: text })
});

🐛 Troubleshooting

LibreTranslate not starting

  • Ensure Docker is running
  • Check port 5000 is not in use
  • Run docker-compose logs for errors

Detection accuracy issues

  • Short text (<10 chars) may be less accurate
  • Consider the hybrid approach prioritizes different detectors based on text length

Translation failures

  • Verify LibreTranslate is running
  • Check network connectivity
  • Ensure target language is supported

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published