icu-l10n is a Node.js-based CLI tool designed for managing ICU (International Components for Unicode) MessageFormat messages in internationalization (i18n) workflows. It supports:
Extraction: Scans source code (JS/TS/JSX/TSX, optionally others) for ICU messages and extracts them into a catalog (JSON or XLIFF).
Validation: Checks ICU syntax, required plural/gender forms, and consistency across locales (e.g., ensuring one, few, other for plurals in languages like Arabic).
TM Population: Exports catalogs to Translation Memory formats (TMX, SDL Trados XML) or uploads to popular TMS like Crowdin, Phrase, or Lokalise via API.
It uses battle-tested libraries:
intl-messageformat-parser for parsing ICU syntax.
glob for file scanning.
commander for CLI parsing.
xliff and tmx writers for export.
Language data from make-plural and CLDR for validation rules.
The tool enforces ICU best practices (RFC 57) and handles complex features like ordinal plurals, genders, and select statements.
Installation
bash
npm install -g @trailblazer/icu-l10n
# Or from source:
git clone https://github.com/trailblazer-labs/icu-l10n-cli.git
cd icu-l10n-cli
npm install && npm link
Requires Node.js >= 18.
Configuration
Create a .icui18nrc.json (or YAML/JS) in your project root:
Purpose: Scans files for ICU patterns (e.g., intl.formatMessage({defaultMessage: '{count, plural, one {1 item} other {# items}}'}) or React Intl JSX) and extracts unique messages into a catalog.
Supports providers via config (Crowdin, Phrase, Lokalise, Transifex). Uses their REST APIs for bulk upload/pre-translation.
Example TMX Output Snippet:
xml
<tu>
<tuv xml:lang="en"><seg>{count, plural, one {1 item} other {# items}}</seg></tuv>
<tuv xml:lang="fr"><seg>{count, plural, one {1 élément} other {# éléments}}</seg></tuv>
</tu>