🌐 Read this in 简体中文.
Translate CLI is a command-line tool that allows users to translate text using the Google Cloud Translation API. Users can input text via standard input, and the tool will return the translated text in the specified target language.
- Supports multiple target languages (default: Simplified Chinese
zh-CN
). - Reads input text from standard input.
- Fetches translations using Google Cloud Translation API.
- Loads API key from a configuration file.
- Uses
.env
for environment variable support.
- Rust (with
cargo
package manager) - A Google Cloud API key with access to the Translation API
.env
file or configuration file specifying the API key
-
Clone the repository:
git clone https://github.com/LogicalMonster/translate-cli.git cd translate-cli
-
Install dependencies:
cargo build --release
-
Move the binary to a directory in your
$PATH
(optional):mv target/release/translate-cli /usr/local/bin/
You need to provide a Google Cloud API key. There are two ways to do this:
-
Using a Configuration File
Create a configuration file (default:~/.translate_cli_config
) with the following content:google_cloud_api_key = "your-api-key-here"
You can also set a custom path using the
TRANSLATE_CLI_CONFIG
environment variable. -
Using
.env
File
Create a.env
file in the project root with the following content:GOOGLE_CLOUD_API_KEY=your-api-key-here
-
Run the program with an optional language code:
echo "Hello, world!" | translate-cli --target=es
Output:
"Hola, mundo!"
-
If no target language is provided, it defaults to Simplified Chinese (
zh-CN
):echo "Hello, world!" | translate-cli
Output:
"你好,世界!"
Flag | Description | Default |
---|---|---|
-t, --target |
Target language code (e.g., es , ja ) |
zh-CN |
reqwest
(HTTP client)serde
andserde_json
(JSON parsing)tokio
(asynchronous runtime)config
(configuration management)clap
(command-line argument parsing)dotenv
(environment variable management)shellexpand
(expands~
in paths)
This project is licensed under the GPL-3.0 License.
Feel free to submit issues or pull requests on GitHub!