Skip to content

CLI Commands

Complete reference for TypeGlot CLI commands.

Global Options

These options work with all commands:

OptionDescription
--helpShow help for a command
--versionShow version number

Commands

init

Initialize TypeGlot in a project.

bash
npx @typeglot/cli init [options]

Options

OptionDescriptionDefault
-l, --locale <code>Source locale codeen
-d, --dir <path>Locales directory./locales

Examples

bash
# Default initialization
npx @typeglot/cli init

# Custom source locale
npx @typeglot/cli init --locale de

# Custom directory
npx @typeglot/cli init --dir ./translations

# Combined
npx @typeglot/cli init -l fr -d ./i18n

Output

Creates:

  • typeglot.config.json
  • {localesDir}/{locale}.json
  • {outputDir}/ directory

build

Compile translation files to TypeScript.

bash
npx @typeglot/cli build [options]

Options

OptionDescriptionDefault
-w, --watchWatch for changesfalse
-v, --verboseVerbose outputfalse

Examples

bash
# Single build
npx @typeglot/cli build

# Watch mode
npx @typeglot/cli build --watch

# Verbose
npx @typeglot/cli build -v

# Watch with verbose
npx @typeglot/cli build -w -v

Output

Generates in outputDir:

  • messages.ts — Typed translation functions
  • {locale}.ts — Locale data for each language
  • index.ts — Main entry point

dev

Start development mode with file watching and dashboard.

bash
npx @typeglot/cli dev [options]

Options

OptionDescriptionDefault
-p, --port <number>Dashboard port3333
--no-uiDisable dashboardfalse

Examples

bash
# Default
npx @typeglot/cli dev

# Custom port
npx @typeglot/cli dev --port 4000

# Without dashboard
npx @typeglot/cli dev --no-ui

Behavior

  1. Loads configuration
  2. Performs initial compilation
  3. Starts file watcher on localesDir
  4. Launches dashboard (unless --no-ui)
  5. Recompiles on file changes

Press Ctrl+C to stop.


translate

Generate translations using AI.

bash
npx @typeglot/cli translate [options]

Options

OptionDescriptionDefault
-t, --target <locales...>Target localesFrom config
-k, --key <key>Specific key to translateAll keys
--dry-runPreview without changesfalse

Examples

bash
# Translate all missing keys
npx @typeglot/cli translate

# Specific locales
npx @typeglot/cli translate --target es fr

# Specific key
npx @typeglot/cli translate --key checkout_button

# Specific key to specific locales
npx @typeglot/cli translate -k welcome -t es fr de

# Dry run
npx @typeglot/cli translate --dry-run

# Key with glob pattern
npx @typeglot/cli translate --key "user.*"

Behavior

  1. Loads configuration
  2. Reads source locale file
  3. Scans source files for JSDoc context
  4. Identifies missing translations
  5. Sends to AI with context
  6. Writes translated values to locale files

Environment Variables

VariableRequired For
OPENAI_API_KEYOpenAI provider
ANTHROPIC_API_KEYAnthropic provider

check

Validate translation coverage (planned feature).

bash
npx @typeglot/cli check [options]

Options

OptionDescriptionDefault
--coverage <percent>Minimum coverage100
--locales <locales...>Check specific localesAll

Examples

bash
# Check all locales
npx @typeglot/cli check

# Require 90% coverage
npx @typeglot/cli check --coverage 90

# Check specific locales
npx @typeglot/cli check --locales es fr

Exit Codes

CodeMeaning
0Success
1Error (invalid config, compilation failure, etc.)

Verbose Output

Enable verbose logging with --verbose or -v:

bash
npx @typeglot/cli build --verbose

Output includes:

  • Configuration details
  • File paths being processed
  • Compilation timing
  • Key counts per file

Configuration Discovery

The CLI looks for configuration in:

  1. typeglot.config.json
  2. typeglot.config.js
  3. .typeglotrc

Override with TYPEGLOT_CONFIG environment variable:

bash
TYPEGLOT_CONFIG=./custom-config.json npx @typeglot/cli build

Working Directory

Commands run in the current working directory. Use cd to change:

bash
cd packages/web
npx @typeglot/cli build

Piping and Scripts

Commands work well in scripts:

json
{
  "scripts": {
    "i18n:build": "typeglot build",
    "i18n:dev": "typeglot dev",
    "i18n:translate": "typeglot translate",
    "precommit": "typeglot build && git add src/generated/i18n"
  }
}

Released under the MIT License.