TeraiTerai

Usage

Overview of available translation providers for Terai.

Terai supports multiple translation providers, giving you the flexibility to choose the best solution for your needs. Whether you prefer AI-powered translations, traditional machine translation services, or a custom solution, Terai has you covered.

Available Providers

ProviderPackageBest For
AI Translatorai + SDK providerFlexible, high-quality AI translations
Google Cloud@google-cloud/translateEnterprise-grade NMT
AWS Translate@aws-sdk/client-translateAWS ecosystem integration
Azure TranslatorNative fetchMicrosoft ecosystem integration
DeepLdeepl-nodePremium translation quality

Choosing a Provider

For Maximum Flexibility: AI Translator

The AI Translator uses the Vercel AI SDK, supporting any LLM provider (OpenAI, Anthropic, Groq, Google, etc.). This gives you:

  • Choice of models (GPT-4o, Claude, Llama, Gemini)
  • Custom system prompts for domain-specific translations
  • Structured output with variable preservation

For Enterprise Scale: Google Cloud or AWS

Both Google Cloud Translation and AWS Translate offer:

  • High throughput and reliability
  • Pay-per-character pricing
  • Integration with existing cloud infrastructure

For Translation Quality: DeepL

DeepL is renowned for producing the most natural-sounding translations, particularly for European languages. It offers:

  • Superior translation quality
  • Formality options
  • Document translation capabilities

For Microsoft Ecosystem: Azure Translator

Azure Translator integrates seamlessly with:

  • Azure services
  • Microsoft 365
  • Cognitive Services suite

Quick Start

All translation providers follow the same pattern:

import { defineConfig } from '@terai/dev'
// Import your preferred translator factory
import { createSomeTranslator } from '@terai/dev'

const translator = createSomeTranslator({
  // Provider-specific options
})

export default defineConfig({
  projectLocale: 'en-US',
  outLocales: ['es-ES', 'fr-FR', 'de-DE'],
  outDir: './locale',
  translator
})

Then run:

pnpm terai extract   # Extract messages from source code
pnpm terai translate # Translate to target locales

Custom Translators

If none of the built-in providers meet your needs, you can create a custom translator to integrate with any translation service or API.