@zero-intl/cli
v1.0.0
Published
CLI for extracting translation keys from zero-intl components
Readme
@zero-intl/cli
A command-line tool for extracting translation keys from zero-intl <T/> components.
Installation
npm install -g @zero-intl/cliOr use with npx:
npx @zero-intl/cli extract "src/**/*.{ts,tsx}"Usage
Extract translation keys from source files:
zero-intl extract "src/**/*.{ts,tsx}" [options]Options:
-o, --output <file>: Output file path (default:source-translations.json)
Examples:
# Extract to default file (source-translations.json)
zero-intl extract "src/**/*.{ts,tsx}"
# Extract to custom file
zero-intl extract "src/**/*.{ts,tsx}" --output my-translations.json
zero-intl extract "src/**/*.{ts,tsx}" -o my-translations.jsonOutput Format
The CLI outputs JSON in a clean key-value format:
{
"apiKeys.authCodeName": {
"defaultMessage": "Auth Code",
"file": "pages/console/api-keys.tsx"
},
"welcome.title": {
"defaultMessage": "Welcome to Zero Intl!",
"file": "src/components/Welcome.tsx",
"description": "Main welcome title"
}
}Supported Components
The CLI extracts translation keys from <T/> components with the following props:
id(required): The translation keydefaultMessage(optional): Default message textdescription(optional): Description for translators
Example component usage:
import { T } from '@zero-intl/react';
function MyComponent() {
return (
<div>
<T id="welcome.message" defaultMessage="Welcome!" />
<T
id="user.greeting"
defaultMessage="Hello, {name}!"
description="Greeting for logged-in users"
/>
</div>
);
}Integration with Build Tools
Add extraction to your CI pipeline:
- name: Extract translation keys
run: npx @zero-intl/cli extract "src/**/*.{ts,tsx}" --output translations.jsonFeatures
- Fast extraction: Processes TypeScript and TSX files efficiently
- Clean output: Simple JSON format without metadata clutter
- Default output: Automatically saves to
source-translations.json - Error handling: Graceful handling of malformed files
