npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@logistically/i18n-cli

v1.0.3

Published

Enterprise-grade CLI tool for extracting and managing translations in Logistically microservices

Downloads

8

Readme

@logistically/i18n-cli

npm version License: MIT Tests

Enterprise-grade CLI tool for extracting and managing translations in Logistically microservices

🚀 Overview

The @logistically/i18n-cli is a powerful, enterprise-ready command-line tool designed to streamline internationalization (i18n) workflows in microservice architectures. It works seamlessly with the @logistically/i18n library to provide a complete i18n solution for NestJS microservices.

🔗 Complementary to @logistically/i18n

This CLI tool is designed to work with the main @logistically/i18n library:

  • @logistically/i18n: Runtime translation library for NestJS microservices
  • @logistically/i18n-cli: Development tool for managing translations

Complete Workflow:

# 1. Extract translatable strings from your codebase
i18n extract --patterns "*.ts,*.js" --output translation-keys.json

# 2. Generate translation files for multiple languages
i18n generate --languages en,fr,es,ar --output src/translations

# 3. Replace hardcoded strings with translation keys
i18n replace --dry-run  # Preview changes
i18n replace            # Apply changes

# 4. Use @logistically/i18n in your NestJS services

✨ Key Features

  • 🔍 Smart Extraction: Automatically extract translatable strings from TypeScript/JavaScript files
  • 🏗️ File Generation: Generate translation files for multiple languages and services
  • 🔄 String Replacement: Replace hardcoded strings with translation keys
  • 🛡️ Security First: Input validation, output sanitization, and path security
  • 📊 Performance Monitoring: Real-time metrics, progress tracking, and concurrent processing
  • ⚙️ Configuration Management: Environment-based configs with validation
  • 📝 Advanced Logging: Structured logging with context and metadata
  • 🧪 Comprehensive Testing: Full test coverage with enterprise feature tests
  • 🔗 Seamless Integration: Works perfectly with @logistically/i18n library

📦 Installation

Global Installation

npm install -g @logistically/i18n-cli

Local Installation

npm install --save-dev @logistically/i18n-cli

Using npx

npx @logistically/i18n-cli --help

🎯 Quick Start

The most comprehensive i18n CLI for NestJS microservices - automatically detects translatable text using built-in patterns - no configuration needed!

1. Extract Translation Keys

# Extract from current directory (finds hardcoded strings automatically)
i18n extract

# Extract from specific directory
i18n extract ./src

# Extract with custom patterns
i18n extract --patterns "*.ts,*.js" --ignore "node_modules/**"

2. Generate Translation Files

# Generate for all services
i18n generate

# Generate for specific languages
i18n generate --languages en,fr,de

# Generate with custom output
i18n generate --output ./translations

3. Replace Hardcoded Strings

# Replace strings with translation keys
i18n replace

# Dry run (preview changes)
i18n replace --dry-run

# Replace with backup
i18n replace --backup

4. Use with @logistically/i18n

// In your NestJS service
import { TranslationService, T } from '@logistically/i18n';

@Injectable()
export class UserService {
  constructor(private translationService: TranslationService) {}

  async findUser(id: string) {
    const user = await this.userRepository.findById(id);
    if (!user) {
      throw new T('USER.NOT_FOUND', { userId: id });
    }
    return user;
  }
}

🔍 Built-in Extraction Patterns

The CLI comes with comprehensive built-in patterns that automatically detect translatable text in your codebase:

Supported Patterns

  • Exception Messages: throw new Error("User not found")
  • Service Messages: this.translationService.translate("USER.CREATED")
  • Decorator Messages: @T("USER.VALIDATION.REQUIRED")
  • String Literals: "User profile updated successfully"
  • Template Literals: `Welcome ${user.name}!`
  • Concatenated Strings: "User " + userId + " not found"
  • Object Properties: message: "User created successfully"
  • Return Objects: return { message: "Operation successful" }
  • Error Arrays: errors.push(\Validation failed`)`
  • BadRequestException: throw new BadRequestException("Invalid input")
  • ForbiddenException: throw new ForbiddenException("Access denied")
  • NotFoundException: throw new NotFoundException("Resource not found")
  • UnauthorizedException: throw new UnauthorizedException("Authentication required")

Automatic Detection

The CLI automatically scans your TypeScript/JavaScript files and extracts:

  • Hardcoded error messages
  • User-facing strings
  • Validation messages
  • Success/error notifications
  • Service method messages
  • Exception descriptions
  • Object properties and return values
  • Error arrays and validation messages

No configuration needed - just run i18n extract and it will find translatable content automatically!

🏆 Why Choose @logistically/i18n-cli?

| Feature | Our CLI | Other Tools | |---------|----------|-------------| | Framework Support | ✅ Any TS/JS + NestJS native | ❌ React-only or generic | | Enterprise Features | ✅ Security, validation, monitoring | ❌ Basic extraction only | | Extraction Patterns | ✅ 12+ comprehensive patterns | ❌ Limited patterns | | Production Ready | ✅ Built for enterprise | ❌ Development tools | | NestJS Integration | ✅ Native support | ❌ No NestJS focus | | No Dependencies | ✅ No external APIs required | ❌ AI/translation services |

What's NOT Extracted

The CLI intelligently excludes non-user-facing content:

  • Log messages: console.log("Debug info"), logger.info("Internal message")
  • API documentation: JSDoc comments, Swagger descriptions
  • Code comments: // TODO:, /* Implementation notes */
  • Configuration values: Environment variables, config keys
  • Technical strings: File paths, URLs, technical identifiers
  • Test data: Mock data, test fixtures
  • Other decorators: Non-translation decorators like @Injectable(), @Controller()

📋 Commands

Extract Command

Extract translatable strings from your codebase.

i18n extract [options]

Options:

  • --patterns <patterns> - File patterns to search (default: ".ts,.js")
  • --ignore <ignore> - Patterns to ignore (default: "node_modules/**")
  • --output <file> - Output file path (default: "translation-keys.json")
  • --verbose - Enable verbose logging
  • --validate - Enable validation
  • --max-file-size <size> - Max file size in MB
  • --concurrency <number> - Max concurrent processing

Generate Command

Generate translation files for different languages and services.

i18n generate [options]

Options:

  • --input <file> - Input translation keys file
  • --languages <languages> - Languages to generate (default: "en,fr,de")
  • --output <dir> - Output directory
  • --format <format> - Output format (json/yaml)
  • --template - Generate template files
  • --backup - Create backup of existing files

Replace Command

Replace hardcoded strings with translation keys.

i18n replace [options]

Options:

  • --input <file> - Translation keys file
  • --patterns <patterns> - File patterns to process
  • --dry-run - Preview changes without applying
  • --backup - Create backup before replacing
  • --preserve-formatting - Preserve original code formatting

Config Command

Manage CLI configuration.

i18n config <subcommand> [options]

Subcommands:

  • show - Show current configuration
  • validate - Validate configuration
  • set <key> <value> - Set configuration value
  • reset - Reset to default configuration

⚙️ Configuration

Environment Variables

# Environment
NODE_ENV=production                    # development/staging/production
LOG_LEVEL=info                         # debug/info/warn/error
LOG_FORMAT=json                        # text/json
LOG_OUTPUT=both                        # console/file/both
LOG_FILE=/var/log/i18n-cli.log        # Log file path

# Performance
MAX_CONCURRENCY=8                      # Max concurrent file processing
MAX_FILE_SIZE=50                       # Max file size in MB
TIMEOUT=600                            # Operation timeout in seconds

# Security
VALIDATE_INPUTS=true                   # Enable input validation
SANITIZE_OUTPUTS=true                  # Enable output sanitization
MAX_KEY_LENGTH=200                     # Max translation key length

# Features
ENABLE_VALIDATION=true                 # Enable validation features
ENABLE_BACKUP=true                     # Enable backup features
ENABLE_DRY_RUN=true                    # Enable dry run features
ENABLE_PROGRESS_BAR=true               # Enable progress bar

Configuration File

Create .i18n-cli.json in your project root:

{
  "version": "2.0.0",
  "environment": "production",
  "logging": {
    "level": "warn",
    "format": "json",
    "output": "both",
    "filePath": "/var/log/i18n-cli.log"
  },
  "performance": {
    "maxConcurrency": 8,
    "maxFileSize": 50,
    "timeout": 600
  },
  "security": {
    "validateInputs": true,
    "sanitizeOutputs": true,
    "maxKeyLength": 200
  },
  "features": {
    "enableValidation": true,
    "enableBackup": true,
    "enableDryRun": true,
    "enableProgressBar": true
  }
}

🔧 Advanced Usage

Custom Extraction Patterns

You can define custom patterns for extracting specific types of translatable strings.

# Extract only exception messages
i18n extract --custom-patterns "throw new Error"

# Extract template literals
i18n extract --custom-patterns "`${text}`"

# Extract specific function calls
i18n extract --custom-patterns "t('text')"

Multi-Service Architecture

For microservice architectures, you can process multiple services simultaneously.

# Extract from multiple services
i18n extract ./auth-service ./user-service ./payment-service

# Generate for each service
i18n generate --services auth,user,payment

# Replace across all services
i18n replace --services auth,user,payment

CI/CD Integration

Perfect for automated pipelines and continuous integration.

# Extract in CI pipeline
i18n extract --validate --max-file-size 10

# Generate with specific languages
i18n generate --languages en,fr --template

# Replace with dry run
i18n replace --dry-run --backup

Environment-Specific Configuration

Configure different settings for different environments.

# Development environment
NODE_ENV=development i18n extract

# Production environment
NODE_ENV=production i18n extract --validate

# Staging environment
NODE_ENV=staging i18n extract --dry-run

🛡️ Security Features

Input Validation

All inputs are automatically validated for security and correctness:

# Enable strict validation
i18n extract --validate-inputs --max-key-length 100

# Validate file paths
i18n extract --validate-paths

Output Sanitization

Automatically sanitize outputs to prevent security issues:

# Enable output sanitization
i18n extract --sanitize-outputs

# Custom sanitization rules
i18n extract --sanitize-rules "script,alert,confirm"

Path Security

Security checks for file paths to prevent traversal attacks:

# Validate all file paths
i18n extract --validate-paths

# Restrict to specific directories
i18n extract --allowed-paths "./src,./lib"

📊 Performance Features

Concurrent Processing

Process multiple files simultaneously for better performance:

# Process 8 files concurrently
i18n extract --concurrency 8

# Environment variable
MAX_CONCURRENCY=8 i18n extract

File Size Filtering

Skip files that are too large to process efficiently:

# Skip files larger than 50MB
i18n extract --max-file-size 50

# Environment variable
MAX_FILE_SIZE=50 i18n extract

Progress Tracking

Monitor progress with real-time updates:

# Enable progress bar
i18n extract --progress-bar

# Environment variable
ENABLE_PROGRESS_BAR=true i18n extract

Performance Monitoring

Track detailed performance metrics:

# Enable performance monitoring
i18n extract --monitor-performance

# View performance report
i18n extract --performance-report

🧪 Testing

Run All Tests

npm test

Enterprise Tests

npm run test:enterprise

Performance Tests

npm run performance:test

Security Tests

npm run security:audit
npm run security:fix

📚 Documentation

🔗 Integration with @logistically/i18n

Complete Workflow Example

# 1. Extract translations from your NestJS services
i18n extract --patterns "*.ts" --ignore "node_modules/**,dist/**"

# 2. Generate translation files for your microservices
i18n generate --languages en,fr,es,ar --output src/translations

# 3. Replace hardcoded strings with translation keys
i18n replace --dry-run  # Preview changes
i18n replace            # Apply changes

# 4. Use in your NestJS services

NestJS Service Example

import { Injectable } from '@nestjs/common';
import { TranslationService, T } from '@logistically/i18n';

@Injectable()
export class UserService {
  constructor(private translationService: TranslationService) {}

  async findUser(id: string) {
    const user = await this.userRepository.findById(id);
    if (!user) {
      // This will be extracted by the CLI
      throw new T('USER.NOT_FOUND', { userId: id });
    }
    return user;
  }

  async updateProfile(userId: string, data: any) {
    try {
      const result = await this.userRepository.update(userId, data);
      // This will be extracted by the CLI
      return this.translationService.translate('PROFILE.UPDATED', { userId });
    } catch (error) {
      // This will be extracted by the CLI
      throw new T('PROFILE.UPDATE_FAILED', { userId, error: error.message });
    }
  }
}

Translation Files Generated

// src/translations/en.json
{
  "USER.NOT_FOUND": "User not found: ${userId}",
  "PROFILE.UPDATED": "Profile updated successfully for user: ${userId}",
  "PROFILE.UPDATE_FAILED": "Failed to update profile for user ${userId}: ${error}"
}

// src/translations/fr.json
{
  "USER.NOT_FOUND": "Utilisateur introuvable: ${userId}",
  "PROFILE.UPDATED": "Profil mis à jour avec succès pour l'utilisateur: ${userId}",
  "PROFILE.UPDATE_FAILED": "Échec de la mise à jour du profil pour l'utilisateur ${userId}: ${error}"
}

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/onwello/i18n-cli.git
cd i18n-cli

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🙏 Acknowledgments


Enterprise-Grade i18n CLI v1.0.1 - The most comprehensive i18n CLI for NestJS microservices. Built for scale, security, and performance. 🚀