@kabeep/node-translate-cli
v1.4.0
Published
A powerful, secure and feature-rich command line via Google Translation.
Maintainers
Readme
A powerful, secure and feature-rich command line via Google Translation.
English | 简体中文
📖 Introduction
Using the node-translate API in the terminal.
The API bypasses token restrictions. If it is used in large quantities or for business, please support the work of Google Translation, which provides a lot of free credits.
Besides simple text translation, it also provides:
- Auto-detect system language as target language
- Spell autocorrect
- Getting source text from stdin
- Polysemous translation results
- Synonyms of the source text
- Example sentences of the source text
- Phonetic transcription of the source and translated text
- Stable output and error prompts
- Beautiful terminal styling
- Internationalized prompt for terminal
⚙️ Installation
npm install @kabeep/node-translate-cli --saveyarn add @kabeep/node-translate-clipnpm add @kabeep/node-translate-cli🚀 Usage
translate <text> [options]
options:
-f, --from The source language (language to be translated from)
specified as language name or ISO 639-1 code
[string] [default: "auto"]
-t, --to The target language (language to be translated to)
specified as language name or ISO 639-1 code
-e, --engine Select translation engine
[string] [choices: "google", "microsoft"] [default: "google"]
[string] [default: "auto"]
--timeout Timeout duration for the translation request in
milliseconds [number] [default: 30000]
--stdin-timeout You can use this parameter to avoid timeouts if stdin
takes too long (ms) [number] [default: 5000]
-r, --retry Retry attempts for the translation request in case of
failure [number] [default: 0]
-p, --show-phonetics Show the pronunciation of the translated word
[boolean] [default: false]
-s, --show-source Show source text information [boolean] [default: false]
-d, --show-detail Show translated detail information [boolean] [default: false]
-l, --show-list Show supported language list [boolean] [default: false]
--show-code Show supported language code list [boolean] [default: false]
--show-adaptive Show adaptive language [boolean] [default: false]
-v, --version Show version [boolean]
-h, --help Show help info [boolean]Environment Variables
| Name | Description | |:--------------------------|:----------------------------------------------------| | NODE_TRANSLATE_CLI_ENGINE | Specify the translation engine through env variable |
🪄 Examples
Using stdin
echo "test" | translate -f en -t zhUsing iso-639-1 and text parameters
translate "test" --from=en --to=zhUsing language name and capitalized correction
translate "test" --from="ENGLISH" --to="chinese"Adaptive source language
translate "test" -t zhSelf-detection of native language
translate "test" -f enAutocorrect source text
translate "Thunk you"Translate words and show synonyms, polysemy explanations and examples
translate "test" -dTranslate a word, phrase or sentence and show the source text and phonetic symbols
translate "test" -s -pSet API timeout
translate "test" --timeout=60000Set the timeout for the standard input stream
npm view node-translate-cli description | translate --stdin-timeout=30000Set the number of retries when an API request fails
translate "test" -r 2Show supported languages
translate -lShow supported language codes
translate --show-codeShow supported adaptive languages
translate --show-adaptiveShow help information
translate -hShow the version of current
translate -v🧙🏽♂️ Advanced
Using another npm package
npm install -g clipboard-cli
# Use the clipboard-cli to copy translation results to the clipboard
translate 'Translate this sentence to your clipboard' | clipboardUsing the static accessor $() method
git commit -m "$(translate 'feat: your commit content' -t zh)"
Using the pipe | symbol
npm info npm description | translate -t zh
Using the redirection > symbol
translate "这是一段测试文本。" -t en > usage.txt
Translate The Rust-lang Book into your language
curl https://raw.githubusercontent.com/rust-lang/book/master/src/ch01-00-getting-started.md | translate
🔧 Autocorrect
Default: white background
Correct Spelling: yellow background
Detect Language: red background

🐢 Network anomaly
When the network is abnormal, the terminal will change as shown in the figure below (they actually come from the same line).

⌨️ Automatic line wrapping
When a single line of content is too long, the terminal will automatically wrap the line after the title.

🌐 i18n
Quickly contribute your language via ease-to-use node-translate-i18n in locale file are welcome, or notify me via Issues for handling.

🔗 Related
- node-translate - 🦜 A powerful, secure and feature-rich api via Google Translation.
- node-translate-i18n - 🌏 A command-line interface tool for translating localization files to other languages.
- google-translate-cli - Google Translate via CLI.
🤝 Contribution
Contributions via Pull Requests or Issues are welcome.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
