Production Readyv0.1.0Library • Go

gotlai

Go Translation AI - An AI-powered HTML translation engine for Go. Features intelligent SHA-256 caching, context-aware translations, RTL support, and efficient batch processing. The Go counterpart to tstlai.

v0.1.0 Released: Initial release with full HTML translation, in-memory and Redis caching, CLI tool, Go source translation, and comprehensive language support.

Key Features

AI-Powered Translation

Uses OpenAI (GPT-4o-mini by default) for high-quality, context-aware translations.

Intelligent Caching

SHA-256 based caching with TTL support. In-memory or Redis backends.

RTL Support

Automatic dir="rtl" for Arabic, Hebrew, Persian, Urdu, and more.

Batch Processing

Efficient API usage by batching translations into single requests.

CLI Tool

Command-line interface for translating files with diff mode and dry run support.

Go Source Translation

Translate Go source code strings and comments with GoProcessor.

Retry Logic

Exponential backoff for transient failures with configurable retries.

40+ Languages

Tiered language support with Tier 1 (high quality) and Tier 2 (good quality) languages.

Quick Start

Installation

go get github.com/ZaguanLabs/gotlai

Basic Usage

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/ZaguanLabs/gotlai"
    "github.com/ZaguanLabs/gotlai/cache"
    "github.com/ZaguanLabs/gotlai/processor"
    "github.com/ZaguanLabs/gotlai/provider"
)

func main() {
    // Create OpenAI provider
    p := provider.NewOpenAIProvider(provider.OpenAIConfig{
        APIKey: os.Getenv("OPENAI_API_KEY"),
        Model:  "gpt-4o-mini",
    })

    // Create translator with cache and HTML processor
    t := gotlai.NewTranslator("es_ES", p,
        gotlai.WithCache(cache.NewInMemoryCache(3600)),
        gotlai.WithProcessor(processor.NewHTMLProcessor()),
        gotlai.WithContext("E-commerce website"),
        gotlai.WithExcludedTerms([]string{"API", "SDK"}),
    )

    // Translate HTML
    html := `<html><body><h1>Welcome</h1><p>Hello World</p></body></html>`
    result, err := t.ProcessHTML(context.Background(), html)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.Content)
    fmt.Printf("Translated: %d, Cached: %d\n", result.TranslatedCount, result.CachedCount)
}

CLI Tool

Installation

go install github.com/ZaguanLabs/gotlai/cmd/gotlai@latest

Usage Examples

# Translate a file
gotlai --lang es_ES input.html > output.html

# Translate with context
gotlai --lang ja_JP --context "E-commerce website" input.html -o output.html

# Exclude terms from translation
gotlai --lang de_DE --exclude "API,SDK,HTML" input.html

# Read from stdin
cat input.html | gotlai --lang fr_FR > output.html

# Diff mode - see what changed between versions
gotlai --lang es_ES --diff old.html new.html

# Dry run - preview without API calls
gotlai --lang es_ES --dry-run input.html

# JSON output for programmatic use
gotlai --lang es_ES --json input.html

CLI Options

--langTarget language (required)
--sourceSource language (default: en)
--output, -oOutput file path
--contextTranslation context hint
--excludeComma-separated terms to skip
--modelOpenAI model (default: gpt-4o-mini)
--diffCompare with previous version
--dry-runPreview without API calls
--jsonOutput as JSON

Caching

In-Memory Cache

c := cache.NewInMemoryCache(3600) // TTL in seconds

Redis Cache

c, err := cache.NewRedisCache(cache.RedisConfig{
    URL:       "redis://localhost:6379",
    TTL:       3600,
    KeyPrefix: "gotlai:",
})

Cache Export/Import

// Export translations for offline use
exporter := cache.NewExporter(myCache)
exporter.ExportToFile("translations.json", map[string]string{"lang": "es_ES"})

// Import translations
importer := cache.NewImporter(newCache)
importer.ImportFromFile("translations.json")

Advanced Features

Go Source Translation

Translate Go source code strings and comments:

proc := processor.NewGoProcessor()

// Or customize:
proc := processor.NewGoProcessor(
    processor.WithComments(true),
    processor.WithStrings(true),
)

Rate Limiting

provider := gotlai.NewRateLimitedProvider(openaiProvider, gotlai.RateLimitConfig{
    RequestsPerMinute: 60,
    BurstSize:         10,
})

Parallel Cache Lookups

translations, misses := gotlai.ParallelCacheLookup(cache, nodes, "es_ES")

Supported Languages

Tier 1 (High Quality)

en_US, en_GB, de_DE, es_ES, es_MX, fr_FR, it_IT, ja_JP, pt_BR, pt_PT, zh_CN, zh_TW

Tier 2 (Good Quality)

ar_SA, ko_KR, ru_RU, nl_NL, pl_PL, tr_TR, vi_VN, and more...

RTL Languages

Arabic (ar), Hebrew (he), Persian (fa), Urdu (ur), Pashto (ps), Sindhi (sd), Uyghur (ug)

Configuration Options

gotlai.NewTranslator("es_ES", provider,
    gotlai.WithSourceLang("en"),              // Source language (default: "en")
    gotlai.WithCache(cache),                  // Translation cache
    gotlai.WithProcessor(processor),          // Content processor
    gotlai.WithExcludedTerms([]string{"API"}), // Terms to never translate
    gotlai.WithContext("Technical docs"),     // Global context for AI
)

Start Translating with Go

High-performance AI translation for your Go applications. Intelligent caching, RTL support, and more.