2 releases
| 0.1.1 | Mar 4, 2025 |
|---|---|
| 0.1.0 | Jan 13, 2025 |
#281 in Internationalization (i18n)
111 downloads per month
32KB
696 lines
install
cargo install intl-cli
CLI Usage Guide
Overview
This is a CLI tool for handling internationalization (i18n) text and translation. It supports the following commands:
- extract: Extract i18n text from files.
- tencent-translate: Translate text using the Tencent Translation service.
Commands and Arguments
extract Command
Used to extract i18n text from specified files.
Notice
The
extractcommand only extracts the strings contained within the$tfunction, such as$t('some words')and$t("after {count} days", {count: 1}).
Usage:
intl-cli extract [OPTIONS]
Options:
| Short | Long | Description | Default |
|---|---|---|---|
-o |
--output |
Output file path | output.json |
-e |
--excludes |
Glob patterns for files to exclude | ["**/node_modules/**", "**/.git/**"] |
-i |
--includes |
Glob patterns for files to include | ["*.{ts,tsx}"] |
-d |
--delete_unreached |
Delete unreached key-value pairs in output | None (default: false) |
Example:
intl-cli extract -o extracted.json -i "*.{ts,tsx}" -e "**/node_modules/**" --delete_unreached
tencent-translate Command
Translate text using the Tencent Translation service.
Usage:
intl-cli tencent-translate [OPTIONS]
Options:
| Short | Long | Description | Default |
|---|---|---|---|
-i |
--input |
Input file path | output.json |
-o |
--output |
Output file path | None |
-s |
--source |
Source language | zh |
-t |
--target |
Target language | en |
-p |
--project_id |
Tencent Translation service Project ID | 0 |
-d |
--secret_id |
Tencent Translation service Secret ID | None |
-k |
--secret_key |
Tencent Translation service Secret Key | None |
-w |
--write_all |
Translate and write all content from input to output | None (default: false) |
Example:
intl-cli tencent-translate -i input.json -o translated.json -s zh -t en --secret_id YOUR_SECRET_ID --secret_key YOUR_SECRET_KEY --write_all
Global Options
| Short | Long | Description |
|---|---|---|
-h |
--help |
Show help message |
-V |
--version |
Show version information |
Example Commands
-
Extract i18n text and save to
i18n.json, ignoringnode_modulesand.gitdirectories:intl extract -o i18n.json -i "*.{ts,tsx}" -e "**/node_modules/**" --delete_unreached -
Use the Tencent Translation service to translate
i18n.jsoninto English and save totranslated.json:intl-cli tencent-translate -i i18n.json -o translated.json --secret_id YOUR_SECRET_ID --secret_key YOUR_SECRET_KEY --write_all
Notes
- When using the
tencent-translatecommand, you must providesecret_idandsecret_key, otherwise the Tencent Translation service cannot be invoked. - The
write_alloption determines whether to translate and write all content from the input to the output.
Dependencies
~28–46MB
~650K SLoC