🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More β†’
Socket
Book a DemoSign in
Socket

localize-ai

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localize-ai

AI-powered React localization with AST-based extraction, namespace-based loading, smart caching, debug mode and multi-provider support

latest
Source
npmnpm
Version
1.5.1
Version published
Weekly downloads
37
825%
Maintainers
1
Weekly downloads
Β 
Created
Source

localize-ai

AI-powered React localization with AST-based extraction, namespace-based loading, and smart caching ⚑

πŸ‘‰ No regex. No manual cleanup. Just accurate and scalable translations.

Context-aware AI localization with multi-provider support ⚑

Automatically extract, translate, and serve multilingual UI β€” powered by AI ⚑

Designed for performance: no unnecessary data, no re-fetching, minimal bundle impact.

✨ Features

πŸ”§ Core

  • πŸ” AST-based extraction (no regex)
  • 🧩 Supports template literals with variables
  • 🧹 Removes unused (dead) translations automatically
  • 🌍 AI-powered translations (OpenAI, Gemini)
  • ⚑ Incremental translation (only new strings/languages)

⚑ Performance

  • Namespace-based splitting
    β†’ Each language is split into namespaces (common.json, dashboard.json, etc.)

  • Lazy loading
    β†’ Only loads required namespace instead of entire language

  • Caching
    β†’ Prevents repeated fetches per language + namespace

βš›οΈ Developer Experience

  • 🧠 Zero-config runtime
  • βš›οΈ React hooks + context
  • 🧠 Context-aware translations
  • πŸ’Έ Cost optimized (no re-translation)
  • 🐞 Debug mode (highlight translated & missing strings in UI)
  • πŸ§ͺ Dry-run mode (preview extraction & translation without modifying files)

⚑ Performance Optimizations

localize-ai is optimized for production:

  • Per-locale splitting β†’ Each language is stored separately (translations_en.json, translations_hi.json)
  • Lazy loading β†’ Only loads the active language instead of all translations
  • Caching β†’ Prevents repeated fetches and improves performance

πŸ‘‰ This ensures fast load times and minimal bundle size.

🧠 Smart Extraction (AST-based)

Localize-ai uses AST parsing instead of regex, ensuring accurate extraction:

  • Handles complex code patterns
  • Supports template literals with variables
  • Avoids false positives

Example:

t(`hello {{userName}}, your order {{id}} is ready`, {
  userName,
  id: orderId
});

πŸ‘‰ Variables are preserved and translated correctly.

🧩 Namespace-based Loading

Localize-ai supports namespace-based translation splitting for large applications:

public/
  └── locales/
      β”œβ”€β”€ en/
      β”‚   β”œβ”€β”€ common.json
      β”‚   β”œβ”€β”€ dashboard.json
      β”‚   β”œβ”€β”€ checkout.json
      β”‚   └── ...
      β”œβ”€β”€ fr/
      β”‚   β”œβ”€β”€ common.json
      β”‚   β”œβ”€β”€ dashboard.json
      β”‚   └── ...

Why this matters:

  • Loads only required translations
  • Improves performance for large apps
  • Reduces initial bundle size

πŸ‘‰ No more loading the entire language file at once.

πŸš€ Smart Caching

Localize-ai caches translations per:

  • language
  • namespace

This ensures:

  • no duplicate network requests
  • faster UI rendering
  • better runtime performance

🐞 Debug Mode

localize-ai provides a built-in debug mode to visualize translation status directly in your UI.

Enable debug mode:

<LanguageContextProvider debug={true}>
  <App />
</LanguageContextProvider>

Behavior: 🟒 Translated strings β†’ highlighted in green 🟑 Missing translations β†’ highlighted in custom color

Configure debug color:

// localize.config.js
export default {
  sourceLanguage: "en",
  translationLanguages: ["hi", "fr", "es", "ar"],
  provider: "gemini",
  apikey: "VITE_GEMINI_API_KEY",
  debugColor: "yellow",
  context: "Kit kat condolence message page"
};

πŸ‘‰ Helps quickly identify missing translations during development.

πŸ§ͺ Dry Run Mode

localize-ai supports a dry-run mode to preview the entire localization pipeline without writing any translations.

Run dry-run:

npx localize-ai translate --dry-run

What it does:

  • Extracts strings using AST
  • Validates template literals
  • Detects missing / partial translations
  • Shows summary without modifying files
  • Example output:
πŸ§ͺ Running dry-run (no translations will be made)...

❌ Invalid template literal detected
πŸ“„ File: src/App.jsx
πŸ“ Line: 82
πŸ‘‰ Use {{var}} instead of ${var}

βœ… Extraction complete with namespaces
βœ… Cleaned namespaces: 2

πŸš€ Starting localization pipeline
ℹ️  Provider: gemini
ℹ️  Source Language: en
ℹ️  Target Languages: hi, fr, es, ar

πŸ“Š Summary:
   Total input strings: 22
   πŸ†• New strings: 0
   🌐 Missing translations: 0
   ⚠️ Partial translations: 0
   Translated now: 0
   Total stored translations: 22

βœ… Done

Why use dry-run? πŸ›‘οΈ Safe preview before running translations πŸ” Catch errors (like invalid template literals) πŸ“Š Understand translation coverage

πŸ‘‰ Ideal for CI checks and debugging.

πŸ“¦ Installation

npm install localize-ai

βš™οΈ Setup (2 steps)

1️⃣ Create config

// localize.config.js
export default {
  sourceLanguage: "en",
  translationLanguages: ["hi", "fr"],
  provider: "gemini", // or "openai"
  apikey: "VITE_GEMINI_API_KEY",
  context: "E-commerce checkout UI for buying products",
};

πŸ‘‰ Providing context improves translation accuracy by helping AI understand intent (e.g., "Charge" in payments vs battery).

2️⃣ Add your API key

VITE_GEMINI_API_KEY=your_api_key_here

πŸš€ Usage

Step 1: Initialize

npx localize-ai init

Step 2: Extract & translate

npx localize-ai translate

This will:

  • scan your codebase
  • extract t("text")
  • generate translations
  • create per-language translation files:
public/
  └── locales/
      β”œβ”€β”€ en/
      β”‚   β”œβ”€β”€ common.json
      β”‚   β”œβ”€β”€ [namespace].json
      β”‚   └── ...
      β”œβ”€β”€ fr/
      β”‚   └── ...

localize.runtime.json

Step 3: Wrap your app

import { LanguageContextProvider } from "localize-ai";

<LanguageContextProvider>
  <App />
</LanguageContextProvider>;

Step 4: Use translations

Using namespaces

const { t } = useTranslation("dashboard");

πŸ‘‰ Loads only dashboard.json for the active language.

If no namespace is provided:

const { t } = useTranslation();

πŸ‘‰ Uses common.json by default.

🌍 Change language

const { setLang } = useTranslation();

setLang("fr"); // switch language

🧹 Dead Translation Cleanup

npx localize-ai delete-sync

Localize-ai automatically removes unused translations:

  • Detects strings no longer present in code
  • Cleans up translation files
  • Keeps JSON lean and optimized

πŸ‘‰ Prevents bloated translation files over time.

🧠 How it works

Code β†’ AST Extract β†’ Namespace Split β†’ AI Translate β†’ JSON β†’ Lazy Load β†’ Cache β†’ UI
  • Only new strings are translated
  • Only missing languages are generated
  • Existing translations are reused

πŸ“ Output

public/
  └── locales/
      β”œβ”€β”€ en/
      β”‚   β”œβ”€β”€ common.json
      β”‚   β”œβ”€β”€ [namespace].json
      β”‚   └── ...
      β”œβ”€β”€ fr/
      β”‚   └── ...

⚑ Example

<h1>{t("Get started")}</h1>

➑️ Automatically becomes:

{
  "common": {
    "Get started": "ΰ€Άΰ₯ΰ€°ΰ₯‚ ΰ€•ΰ€°ΰ₯‡ΰ€‚"
  }
}

πŸ›  CLI Commands

npx localize-ai init        # generate runtime config
npx localize-ai translate   # extract + translate
npx localize-ai delete-sync   # delete dead translations
npx localize-ai translate --dry-run   # preview without writing files

🎯 Why localize-ai?

Featurelocalize-aitraditional i18n
Auto extractionβœ…βŒ
AST-based parsing (no regex)βœ…βŒ
AI translationβœ…βŒ
Incremental updatesβœ…βŒ
Namespace-based loadingβœ…βš οΈ manual
Lazy loadingβœ…βš οΈ manual
Built-in cachingβœ…βŒ
Dead translation cleanupβœ…βŒ
Context-aware translationsβœ…βŒ
Setup time⚑ minutes⏳ hours

⚠️ Notes

  • Only static strings inside t("...") are extracted
  • Ensure public/ folder exists
  • API key is required only for translation step

πŸ—Ί Roadmap

Core Improvements

  • AST-based extraction (no regex)
  • Template literal support with variables
  • Better error handling & retry logic for failed translations
  • CLI UX improvements (spinners, better logs)

Performance & Scalability

  • Lazy loading translations
  • Namespace-based splitting
  • Per-locale structure
  • Smart caching (per language + namespace)
  • CDN support for translation files

Features

  • Multi-provider support (OpenAI, Gemini)
  • Fallback providers (auto-switch if one fails)
  • Custom translation rules (skip/override specific keys)
  • Namespace configuration (custom naming & grouping)

Developer Experience

  • VS Code extension (highlight untranslated strings)
  • Debug mode (show missing translations in UI)
  • CLI dry-run mode
  • Type-safe translations (TS support for keys)

Maintenance & Optimization

  • Dead translation cleanup
  • Translation validation (detect missing/interpolated variables)
  • Sync check (detect outdated translations)

Future Ideas

  • Framework support beyond React (Next.js, Vue)
  • Web dashboard for managing translations
  • Analytics (missing keys, usage tracking)
  • Collaboration support (teams & workflows)

🀝 Contributing

PRs welcome! Feel free to open issues or suggest improvements.

πŸ“„ License

MIT

πŸ’¬ Author

Parth Gupta

⭐ Support

If you like this project:

πŸ‘‰ Star the repo πŸ‘‰ Share with developers πŸ‘‰ Give feedback

Keywords

localization

FAQs

Package last updated on 14 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts