DEV Community

Alexis Clarembeau
Alexis Clarembeau

Posted on

A new tool to manage your i18n locale files

🌐 CLI18n: The Translation Management Tool Your JavaScript Project Needs

Managing internationalization (i18n) in JavaScript projects can be a real pain. Scattered translation keys, duplicate values, unused translations cluttering your locale files, and the constant back-and-forth between code and translation files. Sound familiar?

I've been working on CLI18n – a powerful CLI tool that tackles these exact problems and makes managing translations actually enjoyable.

What is CLI18n?

CLI18n is a comprehensive internationalization management tool that helps you extract, organize, and maintain translation keys in your JavaScript projects. Think of it as your i18n Swiss Army knife.

πŸš€ Key Features

  • πŸ” Smart Key Extraction: Automatically scan your codebase and extract translation keys using customizable regex patterns
  • πŸ”„ Duplicate Detection: Find duplicate translations across locale files to maintain consistency
  • πŸ—‘οΈ Cleanup Tools: Remove unused translations to keep your locale files clean
  • 🌐 Web Interface: Beautiful, responsive web UI for managing translations
  • ⚑ Real-time Editing: Edit translations with instant file updates
  • 🎯 Smart Filtering: Focus on untranslated keys or search specific terms
  • πŸ“± Mobile-Friendly: Works seamlessly on any device

Getting Started

Installation

# Global installation
npm install -g cli18n

# Or use locally
npm install --save-dev cli18n

# Or run without installing
npx cli18n extract
Enter fullscreen mode Exit fullscreen mode

Quick Setup

Create a cli18n.json in your project root:

{
  "regex": "t\\('([^']*)'\\)",
  "outputDir": "locales/{{lang}}.json",
  "languages": ["en", "fr", "es", "de"]
}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Real-World Usage

1. Extract Translation Keys

cli18n extract
Enter fullscreen mode Exit fullscreen mode

This scans your entire codebase, finds patterns like t('welcome.message'), and automatically generates/updates your locale files while preserving existing translations.

2. Find Duplicate Translations

cli18n duplicates
Enter fullscreen mode Exit fullscreen mode

Ever had the same translation value scattered across different keys? This command finds them all, helping you maintain consistency and reduce redundancy.

3. Clean Up Unused Keys

cli18n prune-unused
Enter fullscreen mode Exit fullscreen mode

Over time, translation keys pile up. This command removes keys that are no longer referenced in your codebase, keeping your locale files lean and maintainable.

4. Visual Translation Management

cli18n serve
Enter fullscreen mode Exit fullscreen mode

This launches a beautiful web interface where you can:

  • Browse all translation keys in a clean table
  • Edit translations inline with auto-save
  • Filter by language or search for specific keys
  • Focus on untranslated keys (highlighted in red)
  • Work on mobile or desktop

🎯 Perfect For These Scenarios

Migrating an existing project to i18n? CLI18n can scan your entire codebase and extract all the hardcoded strings you need to translate.

Working with a translation team? The web interface makes it easy for non-technical team members to contribute translations.

Maintaining a large multilingual app? The duplicate detection and cleanup tools keep your translations organized as your project grows.

Starting a new international project? Set up your i18n workflow from day one with automated extraction and management.

Example Project Structure

my-project/
β”œβ”€β”€ cli18n.json
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── Header.js       // t('nav.home'), t('nav.about')
β”‚   └── pages/
β”‚       └── Login.js        // t('login.title'), t('login.submit')
└── locales/
    β”œβ”€β”€ en.json             // Auto-generated
    β”œβ”€β”€ fr.json             // Auto-generated
    └── es.json             // Auto-generated
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Programmatic API

You can also integrate CLI18n into your build process:

const { extractTranslations, findDuplicateTranslations } = require('cli18n');

// In your build script
await extractTranslations();
await findDuplicateTranslations();
Enter fullscreen mode Exit fullscreen mode

Why I Built This

After working on several international JavaScript projects, I kept running into the same issues:

  • Manual translation key management was error-prone
  • Finding unused translations was nearly impossible
  • Non-technical team members struggled with JSON files
  • Duplicate translations created inconsistent UX

CLI18n solves all these problems with a workflow that actually scales.

What's Next?

I'm actively working on CLI18n and have some exciting features planned:

  • Integration with popular translation services
  • VS Code extension for inline translation editing
  • Advanced analytics and translation progress tracking
  • Support for more file formats beyond JSON

Try It Today!

npx cli18n extract
Enter fullscreen mode Exit fullscreen mode

That's it! CLI18n will guide you through the setup and start managing your translations immediately.


Links:

Have you tried CLI18n? What i18n challenges are you facing in your projects? Let me know in the comments!

Top comments (1)

Collapse
 
xaviermac profile image
Xavier Mac

Timely toolβ€”after Unicode 16.0 shipped last fall with new scripts and emoji, keeping locale files clean is even tougher. CLI18n's extract + prune flow looks perfect. Any plans for MessageFormat 2/ICU plural support or integrations with DeepL/Google Translate?