Loading... Build Passing Zero Deps ... Downloads

h56-translator

Lightweight translation service supporting 100+ languages. Zero dependencies, robust server-side Node.js client.

npm install h56-translator
h56@localhost: ~/projects
Indonesian
Detect Language
English
Input Detected
Neural Processing

THE BEST TRANSLATOR EVER MADE BY HASYIM56

Developer Friendly Ecosystem

Overview

h56-translator is a lightweight, blazing fast client for text translation across 100+ languages. Built specifically for server-side Node.js environments demanding zero external dependencies.

Two translation modes:

  • v1: Standard, professional translations with high accuracy.
  • v2 Informal: Conversational translations reflecting natural language usage.

Package Analytics

Real-time ecosystem insights and community adoption metrics for h56-translator, fetched live directly from the NPM Registry.

Total Downloads

Loading...

Weekly Downloads

Loading...

Dependency Status

Secure (0)

Last Publish

Loading...
NPM Embed Stats

Monthly Download Trend

Last 6 Months

Installation

npm install h56-translator

Node.js Requirement: >= 18.0.0 (Utilizes the native global Fetch API)

Requirements

  • Node.js 18.0.0 or higher.
  • Stable network connectivity to the translation API endpoint.
  • Strictly zero external dependencies required.

API Reference

Exports

CommonJS:

const { translate, translateV2, supportedLanguages } = require('h56-translator');

ES Modules:

import { translate, translateV2, supportedLanguages } from 'h56-translator';

Function Signatures

v1 - Standard Translation

function translate(text: string, targetLang: string): Promise<TranslationResult>
  • Parameters:
    • text (string, required): Content to translate
    • targetLang (string, required): Target language code (e.g., 'en', 'id') or language name
  • Returns: Promise resolving to a TranslationResult object

v2 - Informal Translation

function translateV2(text: string, targetLang: string): Promise<TranslationResult>
  • Parameters: Similar to v1.
  • Returns: Promise resolving to a TranslationResult object

Response Structure

interface TranslationResult {
  translatedText: string;         // Translated content
  sourceLang: string;             // Detected source language code
  targetLang: string;             // Requested target language code
  serviceStatus: 'ok' | 'error';  // Operation status
  raw?: any;                      // Complete API response (optional)
}

Error Handling

Thrown Errors:

  • Missing inputs: "text dan targetLang wajib diisi"
  • Unsupported language: "bahasa respon tidak didukung atau tidak ada"
  • Network/API failure: "API error: {status}"
  • Fetch unavailable: "fetch is not available in this environment..."

Usage Examples

v1 Translation

Standard, formal translation for professional content architecture:

const { translate } = require('h56-translator');

(async () => {
  try {
    const result = await translate('Halo dunia', 'en');
    console.log(result.translatedText); // "Hello world"
    console.log(result.sourceLang);     // "id"
    console.log(result.targetLang);     // "en"
  } catch (err) {
    console.error('Translation failed:', err.message);
  }
})();

v2 Translation

Informal, conversational translation for chat applications or casual UI:

const { translateV2 } = require('h56-translator');

(async () => {
  try {
    const result = await translateV2('Apa kabar?', 'en');
    console.log(result.translatedText); 
    // Outputs naturally: "What's up?", "Hey, how you doing?"
  } catch (err) {
    console.error('Error:', err.message);
  }
})();

List Supported Languages

const { supportedLanguages } = require('h56-translator');

// Find specific language seamlessly
const french = supportedLanguages.find(l => l.code === 'fr');
console.log(french); // { code: 'fr', name: 'French', country: 'FR' }

HTTP Contract

v1 Endpoint

URL: https://h56-translator-api.vercel.app/api/translate
Method: POST

{
  "text": "Halo dunia",
  "targetLang": "en"
}

v2 Endpoint

URL: https://h56-translator-api.vercel.app/api/translate/v2
Method: POST

{
  "text": "Apa kabar?",
  "targetLang": "en"
}

Integration Patterns

Request Cancellation

Abort long-running network requests effectively using AbortSignal:

const controller = new AbortController();
setTimeout(() => controller.abort(), 10000); // 10s timeout threshold

try {
  const result = await translate('Teks panjang...', 'en', { signal: controller.signal });
} catch (err) {
  if (err.name === 'AbortError') console.log('Request Gracefully Cancelled');
}

Security Architecture

  • Zero dependencies: Absolute minimal attack surface avoiding supply-chain vulnerabilities.
  • Stateless processing: No persistent data stored; tone and style preferences exist only within the ephemeral request scope.
  • HTTPS strictly enforced: All API communication is robustly encrypted.
  • Strict Input validation: Language codes are strictly verified against an internal supported lexicon list.

License & Open Source

MIT © Muhammad Ali Hasyim

Repository: GitHub
Issues: Issue Tracker
Author: HASYIM56