Skip to main content

Translate text by google, bing, youdaozhiyun, haici, stardict, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim.

Project description

translate-shell

pre-commit.ci status github/workflow codecov readthedocs DeepSource

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

Translate text by google, bing, youdaozhiyun, haici, stardict, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim.

Usage

UI

CLI

trans --translators=google,bing,haici,stardict crush

CLI

REPL

$ trans  # enter REPL
> en:ja  # change source language to english and target language to japanese
> :  # swap source and target languages
> =stardict  # use stardict to translate text
> !cat example/test.txt  # execute a shell command
ハッカー
> <example/test.txt   # translate a file
hacker
> 画家  # translate text
painter; artist
> !  # enter shell
$ echo $SHELL  # execute a shell command
/usr/bin/zsh
$ exit  # exit shell
>

REPL

TUI

Vim
Translate --translators=google,bing Free as in Freedom

Vim

GUI

GNU/Linux

GNU/Linux

Android

android-toast

Script

Python

>>> from translate_shell.translate import translate
>>> translate("The Mythical Man-Month", "zh_TW")
... Translation(
...     status=1,
...     results=[
...         {
...             "translator": "google",
...             "sl": "auto",
...             "tl": "zh_TW",
...             "text": "The Mythical Man-Month",
...             "phonetic": "",
...             "paraphrase": "人月神話",
...             "explains": {},
...             "details": {},
...             "alternatives": ["神话般的人月"],
...         }
...     ],
...     text="The Mythical Man-Month",
...     to_lang="zh_TW",
...     from_lang="auto",
... )

Shell Script

$ xsel -o | trans --format json | jq -r '"《\(.results[].paraphrase)》的英文是 \(.text)."'
《大教堂和集市》的英文是 the cathedral and the bazaar.

Vim Script

:let g:text = 'Just for Fun'
:let g:translation = json_decode(translate_shell#call('--format=json', g:text))
:echo g:text 'is' g:translation.results[0].paraphrase 'in Chinese.'
Just for Fun is 纯娱乐 in Chinese.

Similar Projects

See comparison.

Features

  • Translate with different translators at same time, like translator
  • Translate clipboard contents automatically, like ydcv
  • Speak the pronunciation of words
  • Support online translate engines
  • Support offline dictionaries
  • Many methods to use, from shell, python and vim
  • Magic text, like en: to change source language, :zh_CN to change target language, <file to translate file, etc.
  • Allow customization by config.py
  • Good shell completions, especially for zsh, complete options and translation history
  • Manpage: man trans
  • Beautiful UI
  • Cross platforms
  • Rich API, can be easily called from shell and python
  • Good document
  • Unit test, keep code quality
  • CI/CD
  • clean code
  • Respect PEP484
  • Respect PEP621
  • Respect XDG

The last but not least: it is a libre software.

See document to know more.

PS: PR is welcome! Please make code clean and keep test pass!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

translate-shell-0.0.25.tar.gz (100.5 kB view details)

Uploaded Source

Built Distribution

translate_shell-0.0.25-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file translate-shell-0.0.25.tar.gz.

File metadata

  • Download URL: translate-shell-0.0.25.tar.gz
  • Upload date:
  • Size: 100.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for translate-shell-0.0.25.tar.gz
Algorithm Hash digest
SHA256 199391818fed6f18944d2134f0d6eb99de9f1c3806587ffffa53c4045065b408
MD5 39432f345a510bb9ca8f9da0a1bc57bb
BLAKE2b-256 24d23d78481e90ed08a2156b41fa94f450f0d2e54433da2a6da056bebf055f86

See more details on using hashes here.

File details

Details for the file translate_shell-0.0.25-py3-none-any.whl.

File metadata

File hashes

Hashes for translate_shell-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 bfc0bdddac50e045a159344b87991a2505787894c5404b045fa9328a68805d3d
MD5 934e6d34476614286a5d3305c66c8be2
BLAKE2b-256 4c489eaf1e3bfc5c78a09c6f5d1a39501246298a9ef928b9600a32e74d2a5e02

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page