
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
The smarter way to translate: AI-powered, cache-optimized, globally ready.
It intelligently batches and caches translation requests, ensuring blazing-fast results and reducing API calls.
Whether you're building a multilingual website, a mobile app, or a localization tool, GPTrans delivers top-tier performance with minimal setup.
npm install gptrans
GPTrans uses dotenv for environment configuration. Create a .env
file in your project root and add your API keys:
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
Here's a simple example to get you started:
import GPTrans from 'gptrans';
const gptrans = new GPTrans({
from: 'en-US',
target: 'es-AR',
model: 'claude-3-5-sonnet-20241022'
});
// Translate text with parameter substitution
console.log(gptrans.t('Hello, {name}!', { name: 'John' }));
// Set context for gender-aware translations
console.log(gptrans.setContext('Message is for a woman').t('You are very good'));
// Other translation examples
console.log(gptrans.t('Withdraw'));
console.log(gptrans.t('Top-up'));
console.log(gptrans.t('Transfer'));
console.log(gptrans.t('Deposit'));
console.log(gptrans.t('Balance'));
console.log(gptrans.t('Transaction'));
console.log(gptrans.t('Account'));
console.log(gptrans.t('Card'));
When creating a new instance of GPTrans, you can customize:
Option | Description | Default |
---|---|---|
from | Source language locale (BCP 47) | en-US |
target | Target language locale (BCP 47) | es |
model | Translation model key or array of models for fallback | claude-3-7-sonnet |
batchThreshold | Maximum number of characters to accumulate before triggering batch processing | 1500 |
debounceTimeout | Time in milliseconds to wait before processing translations | 500 |
freeze | Freeze mode to prevent translations from being queued | false |
GPTrans uses BCP 47 language tags for language specification. BCP 47 is the standard for language tags that combines language, script, and region codes. Here are some common examples:
en-US
- English (United States)es-AR
- Spanish (Argentina)pt-BR
- Portuguese (Brazil)For simplified or universal language codes, you can omit the region specification:
es
- Spanish (Universal)db/gptrans_<tag>.json
. Subsequent requests for the same text will be served instantly from the cache.prompt/translate.md
file) to fine-tune the translation output.db/gptrans_<tag>.json
file:{
"balanc_pephba": "Saldo",
"transa_m1wmv2": "TransacciΓ³n",
"accoun_rtvnkg": "Cuenta",
"card_yis1pt": "Tarjeta",
"hello_name_1vhllz3": "Β‘Hola, {name}!",
...
}
GPTrans stands out by combining advanced AI capabilities with efficient batching and caching. This means:
If you're looking to streamline your translation workflow and bring your applications to a global audience effortlessly, GPTrans is the perfect choice!
You can preload translations for specific languages using the preload
method. This is particularly useful when you want to initialize translations based on dynamically generated keys:
await gptrans.preload({ target:'ar' });
GPTrans supports a fallback mechanism for translation models. Instead of providing a single model, you can pass an array of models:
const translator = new GPTrans({
model: ['claude-3-7-sonnet-20250219', 'o3-mini-2025-01-31'],
// ... other options
});
When using multiple models:
Contributions are welcome! Please open an issue or submit a pull request on GitHub to contribute improvements or fixes.
GPTrans is released under the MIT License.
Happy translating! πβ¨
FAQs
π GPTrans - The smarter AI-powered way to translate.
The npm package gptrans receives a total of 2 weekly downloads. As such, gptrans popularity was classified as not popular.
We found that gptrans demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.