{"_id":"@dysporium/polyglot-ai","name":"@dysporium/polyglot-ai","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@dysporium/polyglot-ai","version":"1.0.1","description":"AI-powered translation for Dysporium Polyglot","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"keywords":["i18n","ai","translation","openai","claude","anthropic","qwen","llm","polyglot"],"license":"MIT","dependencies":{"@dysporium-sdk/core":"^1.0.0","@dysporium/polyglot-core":"2.0.0"},"peerDependencies":{"@dysporium-sdk/openai":"^1.0.0","@dysporium-sdk/anthropic":"^1.0.0","@dysporium-sdk/qwen":"^1.0.0"},"peerDependenciesMeta":{"@dysporium-sdk/openai":{"optional":true},"@dysporium-sdk/anthropic":{"optional":true},"@dysporium-sdk/qwen":{"optional":true}},"devDependencies":{"tsup":"^8.0.1","typescript":"^5.3.3"},"scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit"},"_id":"@dysporium/polyglot-ai@1.0.1","_integrity":"sha512-Qmth4jwe50Id7HMoi7oAo0OErFR57xJESnnhpSnJaLYGYGfwOhW8tb8Om7A5Wq8crWlG03lxps7g+eeqDoP12w==","_resolved":"/tmp/b4d8a74b5f336fa5b5330f777c537ec8/dysporium-polyglot-ai-1.0.1.tgz","_from":"file:dysporium-polyglot-ai-1.0.1.tgz","_nodeVersion":"20.19.6","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Qmth4jwe50Id7HMoi7oAo0OErFR57xJESnnhpSnJaLYGYGfwOhW8tb8Om7A5Wq8crWlG03lxps7g+eeqDoP12w==","shasum":"3cee9ceee9cc4d091d0acf6373db05cf3f5c2514","tarball":"https://registry.npmjs.org/@dysporium/polyglot-ai/-/polyglot-ai-1.0.1.tgz","fileCount":9,"unpackedSize":89049,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCSTYlNFgsny+AEixPYBdXo7bp4m59H7ChDcCx5tiwkZAIhAIArjizdZk0pZI3dmncuO2RYvWI5wmnwJV7ckcnXwVPS"}]},"_npmUser":{"name":"paulmothapo","email":"paulmothapo.personal@gmail.com"},"directories":{},"maintainers":[{"name":"paulmothapo","email":"paulmothapo.personal@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/polyglot-ai_1.0.1_1767115608759_0.5437724224277822"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-30T17:26:48.613Z","1.0.1":"2025-12-30T17:26:48.912Z","modified":"2025-12-30T17:26:49.220Z"},"maintainers":[{"name":"paulmothapo","email":"paulmothapo.personal@gmail.com"}],"description":"AI-powered translation for Dysporium Polyglot","keywords":["i18n","ai","translation","openai","claude","anthropic","qwen","llm","polyglot"],"license":"MIT","readme":"# @dysporium/polyglot-ai\n\nAI-powered translation for Dysporium Polyglot. Generate translations automatically using large language models through the [Dysporium AI SDK](https://github.com/Dysporium/dysporium-ai-sdk).\n\n## Overview\n\nThis 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.\n\nThe 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.\n\n## Features\n\n### Multiple Provider Support\n\nBuilt-in support through Dysporium AI SDK providers:\n\n- **OpenAI** - GPT-4, GPT-4 Turbo, GPT-4o, GPT-3.5 Turbo\n- **Anthropic** - Claude 3 Opus, Sonnet, Haiku, and Claude 3.5 Sonnet\n- **Qwen** - Alibaba's Qwen models\n- **Custom** - Bring your own provider with a simple interface\n\n### AI Loader\n\nThe 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.\n\n### AI Translator Wrapper\n\nThe 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.\n\n### Automatic Translation\n\nEnable 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.\n\n### Batch Translation\n\nTranslate 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.\n\n### Context-Aware Translation\n\nProvide context to help the AI generate more accurate translations. Context might include information about your application domain, tone preferences, or terminology guidelines.\n\n### Placeholder Preservation\n\nThe 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.\n\n## Installation\n\n**npm**\n\n    npm install @dysporium/polyglot-ai\n\n**pnpm**\n\n    pnpm add @dysporium/polyglot-ai\n\n**yarn**\n\n    yarn add @dysporium/polyglot-ai\n\nThen install your preferred AI provider:\n\n**For OpenAI:**\n\n    npm install @dysporium-sdk/openai\n\n**For Anthropic:**\n\n    npm install @dysporium-sdk/anthropic\n\n**For Qwen:**\n\n    npm install @dysporium-sdk/qwen\n\n\n## Provider Configuration\n\nAll providers accept a model instance from the Dysporium AI SDK along with optional parameters:\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| model | SDK model | required | Model instance from Dysporium SDK provider |\n| maxTokens | number | 4096 | Maximum tokens in response |\n| temperature | number | 0.3 | Sampling temperature |\n\n## AI Loader Configuration\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| provider | AIProvider | required | The AI provider to use |\n| sourceLocale | string | required | Locale of your source translations |\n| sourceTranslations | object | required | Your base translation file |\n| context | string | undefined | Context to improve translation quality |\n| cacheResults | boolean | true | Whether to cache generated translations |\n\n## AI Translator Configuration\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| provider | AIProvider | required | The AI provider to use |\n| sourceLocale | string | required | Locale of your source translations |\n| autoTranslate | boolean | false | Auto-translate missing keys |\n| cacheResults | boolean | true | Whether to cache translations |\n| context | string | undefined | Context for translations |\n\n## Dependencies\n\nThis 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.\n\n## Related Packages\n\n- `@dysporium/polyglot-core` - Core translation engine\n- `@dysporium/polyglot-react` - React hooks and components\n- `@dysporium/polyglot-dom` - Vanilla JS DOM integration\n- [Dysporium AI SDK](https://dysporium.mintlify.app/getting-started) - Unified AI provider interface\n\n## Cost Considerations\n\nAI-powered translation incurs costs based on your provider's pricing. Consider these strategies to manage costs:\n\n- Cache translations aggressively to avoid repeated API calls\n- Generate locale files once and commit them to your repository\n- Use smaller models for development and larger models for production\n- Batch translate during build time rather than at runtime\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-d6e235a99f4cfd70294f3af617759ce3"}