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

@dysporium/polyglot-ai

v1.0.1

Published

AI-powered translation for Dysporium Polyglot

Readme

@dysporium/polyglot-ai

AI-powered translation for Dysporium Polyglot. Generate translations automatically using large language models through the Dysporium AI SDK.

Overview

This package extends Dysporium Polyglot with the ability to generate translations using AI. Instead of manually translating every string in your application, you can provide translations in a source language and let an LLM generate translations for other locales on demand.

The package uses the Dysporium AI SDK under the hood, providing a unified interface across multiple AI providers with type safety, streaming support, and production-ready features like retry logic and error handling.

Features

Multiple Provider Support

Built-in support through Dysporium AI SDK providers:

  • OpenAI - GPT-4, GPT-4 Turbo, GPT-4o, GPT-3.5 Turbo
  • Anthropic - Claude 3 Opus, Sonnet, Haiku, and Claude 3.5 Sonnet
  • Qwen - Alibaba's Qwen models
  • Custom - Bring your own provider with a simple interface

AI Loader

The AILoader implements the standard Dysporium loader interface. When translations for a locale are requested, the loader translates your source translations using the configured AI provider. Results are cached to avoid redundant API calls.

AI Translator Wrapper

The AITranslator wraps your existing Translator instance with AI capabilities. It can automatically translate missing keys on demand, generate entire locale files, or translate specific keys programmatically.

Automatic Translation

Enable auto-translate mode to automatically generate translations for missing keys. When a translation is not found in the current locale, the AI translator fetches the source text and requests a translation from the AI provider.

Batch Translation

Translate multiple keys or entire translation files in a single API call. The batch translation feature optimizes token usage by combining multiple strings into a single request.

Context-Aware Translation

Provide context to help the AI generate more accurate translations. Context might include information about your application domain, tone preferences, or terminology guidelines.

Placeholder Preservation

The AI providers are instructed to preserve interpolation placeholders exactly as they appear in the source text. Placeholders like {{name}} or {count} remain intact in translated output.

Installation

npm

npm install @dysporium/polyglot-ai

pnpm

pnpm add @dysporium/polyglot-ai

yarn

yarn add @dysporium/polyglot-ai

Then install your preferred AI provider:

For OpenAI:

npm install @dysporium-sdk/openai

For Anthropic:

npm install @dysporium-sdk/anthropic

For Qwen:

npm install @dysporium-sdk/qwen

Provider Configuration

All providers accept a model instance from the Dysporium AI SDK along with optional parameters:

| Option | Type | Default | Description | |--------|------|---------|-------------| | model | SDK model | required | Model instance from Dysporium SDK provider | | maxTokens | number | 4096 | Maximum tokens in response | | temperature | number | 0.3 | Sampling temperature |

AI Loader Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | provider | AIProvider | required | The AI provider to use | | sourceLocale | string | required | Locale of your source translations | | sourceTranslations | object | required | Your base translation file | | context | string | undefined | Context to improve translation quality | | cacheResults | boolean | true | Whether to cache generated translations |

AI Translator Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | provider | AIProvider | required | The AI provider to use | | sourceLocale | string | required | Locale of your source translations | | autoTranslate | boolean | false | Auto-translate missing keys | | cacheResults | boolean | true | Whether to cache translations | | context | string | undefined | Context for translations |

Dependencies

This package includes @dysporium/polyglot-core and @dysporium-sdk/core as dependencies. Provider packages (@dysporium-sdk/openai, @dysporium-sdk/anthropic, @dysporium-sdk/qwen) are optional peer dependencies - install only the ones you need.

Related Packages

  • @dysporium/polyglot-core - Core translation engine
  • @dysporium/polyglot-react - React hooks and components
  • @dysporium/polyglot-dom - Vanilla JS DOM integration
  • Dysporium AI SDK - Unified AI provider interface

Cost Considerations

AI-powered translation incurs costs based on your provider's pricing. Consider these strategies to manage costs:

  • Cache translations aggressively to avoid repeated API calls
  • Generate locale files once and commit them to your repository
  • Use smaller models for development and larger models for production
  • Batch translate during build time rather than at runtime

License

MIT