npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

gptrans

v1.8.6

Published

πŸš† GPTrans - The smarter AI-powered way to translate.

Readme

πŸš† GPTrans

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.

✨ Features

  • AI-Powered Translations: Harness advanced models like OpenAI's GPT and Anthropic's Sonnet for high-quality translations
  • Smart Batching & Debouncing: Translations are processed in batches, not only for efficiency but also to provide better context. By sending multiple related texts together, the AI model can better understand the overall context and produce more accurate and consistent translations across related terms and phrases.
  • Caching with JSON: Quickly retrieves cached translations to boost performance
  • Parameter Substitution: Dynamically replace placeholders in your translations
  • Smart Context Handling: Add contextual information to improve translation accuracy. Perfect for gender-aware translations, domain-specific content, or any scenario where additional context helps produce better results. The context is automatically cleared after each translation to prevent unintended effects.

πŸ“¦ Installation

npm install gptrans

🌐 Environment Setup

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
GEMINI_API_KEY=for_image_translations

πŸš€ Quick Start

Here's a simple example to get you started:

import GPTrans from 'gptrans';

const gptrans = new GPTrans({
  from: 'en-US',
  target: 'es-AR',
  model: 'sonnet45'
});

// 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'));

βš™οΈ Configuration Options

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 | sonnet45 gpt41 | | 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 |

BCP 47 Language Tags

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)

πŸ” How It Works

  1. First-Time Translation Behavior: On the first request, Gptrans will return the original text while processing the translation in the background. This ensures your application remains responsive without waiting for API calls.
  2. Translation Caching: Once processed, translations are stored in db/gptrans_<tag>.json. Subsequent requests for the same text will be served instantly from the cache.
  3. Smart Batch Processing: Automatically groups translation requests to optimize API usage and provide better context.
  4. Dynamic Model Integration: Easily plug in multiple AI translation providers with the ModelMix library.
  5. Customizable Prompts: Load and modify translation prompts (see the prompt/translate.md file) to fine-tune the translation output.
  6. Manual Corrections: A JSON file stores key-translation pairs, allowing you to override specific translations and make manual corrections when needed. Simply edit the db/gptrans_<tag>.json file:
{
    "balanc_pephba": "Saldo",
    "transa_m1wmv2": "TransacciΓ³n",
    "accoun_rtvnkg": "Cuenta",
    "card_yis1pt": "Tarjeta",
    "hello_name_1vhllz3": "Β‘Hola, {name}!",
    ...
}

πŸŽ‰ Why Choose GPTrans?

GPTrans stands out by combining advanced AI capabilities with efficient batching and caching. This means:

  • Speed: Reduced API calls and instant retrieval of cached translations
  • Quality: Leverage state-of-the-art models for precise and context-aware translations
  • Flexibility: Tailor the tool to your specific localization needs with minimal effort
  • Zero Maintenance: Set it up once and forget about it - automatic updates and self-healing capabilities keep everything running smoothly

If you're looking to streamline your translation workflow and bring your applications to a global audience effortlessly, GPTrans is the perfect choice!

πŸ”„ Preloading Translations

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' });

Model Fallback System

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: ['claude37', 'gpt41'],
  // ... other options
});

When using multiple models:

  • The first model in the array is used as the primary translation service
  • If the primary model fails (due to API errors, rate limits, etc.), GPTrans automatically falls back to the next model
  • This ensures higher availability and resilience of your translation service

πŸ–ΌοΈ Image Translation

Intelligent image translation using Google's Gemini AI.

Image Translation Example

Original English image (left) β†’ Translated to Spanish (right)*

✨ Smart Path Detection

The translation system automatically detects if your image is already in a language folder and adjusts the output path accordingly:

Example

// Input: en/image.jpg
// Output: es/image.jpg (sibling folder at same level)

const result = await gptrans.img('en/image.jpg');

Directory Structure:

project/
β”œβ”€β”€ en/
β”‚   └── image.jpg          ← Original
└── es/
    └── image.jpg          ← Translation (sibling folder)

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub to contribute improvements or fixes.

License

GPTrans is released under the MIT License.

Happy translating! 🌍✨