TransLang API
April 21, 2025 ยท View on GitHub
A simple translation API that acts as a proxy for Google Translate, built with Deno and Hono.
Features
- REST API with both GET and POST endpoints
- CORS enabled
Installation
- Make sure you have Deno installed on your system.
- Clone this repository.
Usage
Start the server
# Development mode (with auto-reload)
deno task dev
# Debug mode
deno task debug
# Production mode
deno task start
The server will run on http://localhost:8000 by default.
API Endpoints
List Available Endpoints
GET /
Returns a list of available API endpoints.
Translate Text
GET Method
GET /api/v1/translate?text=Hello&sl=en&tl=fr
Parameters:
text: The text to translate (required)sl: Source language code (optional, defaults to 'auto' for auto-detection)tl: Target language code (optional, defaults to 'en')
POST Method
POST /api/v1/translate
Accepts both JSON and form data:
JSON format:
{
"text": "Hello",
"sl": "en",
"tl": "fr"
}
Form data:
text: The text to translatesl: Source language codetl: Target language code
Response Format
{
"detected_language": "en",
"translated_text": "Bonjour",
"pronunciation": null
}
List Supported Languages
GET /api/v1/languages
Returns a JSON object with all supported source (sl) and target (tl) languages.
Cache
Translations may be cached for one week via Cache-Control header to improve performance and reduce API calls.
Development
Available Tasks
deno task dev: Run the server in development mode with auto-reloaddeno task debug: Run the server in debug modedeno task start: Run the server in production modedeno task fetch-languages: Update the languages.json file from Google Translatedeno task count-languages: Count the number of supported languages
Privacy
Please refer to the Privacy Policy for details on how data is handled.