@abc15018045126/translators
v0.1.5
Published
A high-performance, multi-engine translation SDK (Google & Bing) with built-in caching and Manifest V3 compatibility.
Maintainers
Readme
@abc15018045126/translators
🚀 A high-performance, multi-engine translation SDK for Google & Bing, specifically designed for Manifest V3 and high-concurrency environments.
Features
- Three Engine Modes: Use Google, Bing, or the powerful Hybrid mode.
- Hybrid Strategy: Highly configurable. Translate main text with Google while fetching rich dictionary data and examples from Bing.
- Concurrency Control: Built-in request deduplication (In-flight deduplication) and concurrency locks to save bandwidth and prevent redundant token updates.
- Full Platform Compatibility: Native support for Chrome Extension (MV3), Node.js (18+), Webview, and modern browsers.
- Smart Caching: Zero-config LRU cache system for lightning-fast results on repeated queries.
Installation
npm install @abc15018045126/translatorsCore Usage
1. Google Mode (GoogleTranslator)
The classic choice with auto-detection, pronunciation, and automatic TKK update logic.
import { GoogleTranslator } from '@abc15018045126/translators';
const google = new GoogleTranslator();
const res = await google.translate("Stay hungry, stay foolish", "auto", "zh-CN");
console.log(res.mainMeaning); // "求知若渴,虚心若愚"2. Bing Mode (BingTranslator)
A stable alternative that often provides more detailed examples and dictionary definitions in certain regions.
import { BingTranslator } from '@abc15018045126/translators';
const bing = new BingTranslator();
const res = await bing.translate("Magic", "en", "zh-CN");
console.log(res.detailedMeanings); // Detailed POS definitions and synonyms3. Hybrid Mode (HybridTranslator) —— Recommended
The highlight of this SDK. It allows you to combine the best of both worlds.
import { HybridTranslator } from '@abc15018045126/translators';
const hybrid = new HybridTranslator();
// In default config, it intelligently allocates request components
const res = await hybrid.translate("Integrity", "auto", "zh-CN");
console.log(res.mainMeaning); // From Google (usually)
console.log(res.examples); // From Bing (usually)Advanced Features
Warm-Up (Optional)
Reduce first-request latency by pre-fetching necessary tokens:
await translator.warmUp();Pronunciation
Play high-quality audio for any text:
await google.pronounce("Hello", "en", "normal");Credits
This SDK's core scraping and translation logic is based on the Meapri/EdgeTranslate-v3 project. We've modernized the codebase, added MV3 support, and implemented performance optimizations.
License
MIT © abc15018045126
