Skip to main content

A command-line translator was implemented in Plumbum. Google Translate and DeepL Translator and Youdao. Just for fun :)

Project description

Dict-tiny

PyPI version GitHub Workflow Status License: MIT Downloads

A command line translator that integrates with Google Translate, DeepL Translator and youdao.com

Just for fun :)

Installation

You can install dict-tiny via the pip package manager. (Python 3 only)

$ pip install dict-tiny

Upgrading

$ pip install --upgrade dict-tiny

Usage

DeepL Translator

Adding -d / --deepl to use DeepL Translator API:

$ dict-tiny -d easy come easy go
>>> DeepL Translator
detected language: EN
input: easy come easy go
output: 来得容易去得快

Specify the target translation language as French via the --target-language:

$ dict-tiny -d easy come easy go  --target-language FR
>>> DeepL Translator
detected language: EN
input: easy come easy go
output: ça va, ça vient

Note:

  • Make sure the google service is available in your network environment.
  • The target-language parameter is required for deepl translator API. The default target-language is ZH.
  • You can view the list of target languages here.
  • The current account translation quota is 500,000 characters per month. If the quota is exhausted, you can use Google Translate. Enter the content you actually want to translate, please do not abuse this feature.

Google Translation

Adding -g / --google to use Google Translation API:

$ dict-tiny -g book
>>> Google Translate
detected language: en
input: book
output: 

Adding --target-language to specify what language you want to translate into:

$ dict-tiny -g book --target-language japanese
>>> Google Translate
detected language: en
input: book
output: 

Adding --source-language to specify what language you want to translate, but most of the time you don't need to do this because the API will automatically detect the language type.

So, of course, you can use it to detect the language type:

$ dict-tiny --detect-language book
>>> Google detect language
confidence: 1
input: book
language: en
name: English

Note:

  • Make sure the google service is available in your network environment.

  • The source and target languages for Google Translate are identified using the iso-639-1 codes.

    $ dict-tiny -g book --target-language zh --source-language en
    >>> Google Translate
    input: book
    output: 
    source language: en
    

    You can also enter the ISO language name:

    $ dict-tiny -g book --target-language German --source-language English
    >>> Google Translate
    input: book
    output: Buchen
    source language: English
    

Target language

  • Setting the environment variable $DICT_TINY_TARGET_LAN to the target language you prefer so that you do not have to specify the target language every time. Dict-tiny will first get target language from $DICT_TINY_TARGET_LAN. Giving the --target-language switch on the command line will override the environment variable value.
  • The default target-language for Goole Translate and DeepL are ENGLISH_ISO_639='en' and EN-US if you do not specify a target-language includes giving --target-language switch on the command line and setting $DICT_TINY_TARGET_LAN environment variable.

Default behavior

  • If your input is a sentence or more than one word, the DeepL Translator will be called automatically.

  • If your input is a word and you don't add any switch, then the default behavior is to use youdao.com to translate between English and Chinese. In other words, you have to input a Chinese words or an English words, forgive me, because I am an English learner :smile_cat:

$ dict-tiny book
book  [bʊk][bʊk]
===================
n. 书籍账簿名册工作簿
vt. 预订登记
n. (Book)人名()(广东话·威妥玛)()()
$ dict-tiny 
  [shū]
=========
n.book;letter;script
vt.write

Use -m/--more to get more detail translation for word:

$ dict-tiny 曾经 -m
曾经  [céng jīng]
=================
adv.once;ever

more detail:
======== 副词 ========
1:
  表示有过某些行为或情况 once:
  He once lived in Shanghai.
  他曾经在上海住过
  She has taken part in a major battle for oil.
  她曾经参加过石油大会战
$ dict-tiny dictionary -m
dictionary  ['dɪkʃ(ə)n(ə)rɪ]美['dɪkʃə'nɛri]
=============================================
n. 字典词典

more detail (collins):
======== N-COUNT 可数名词 ========
 · 词典

A dictionary is a book in which the words and phrases of a language are listed alphabetically, together with their meanings or their translations in another language.


 : ...a Spanish-English dictionary.
     一本西班牙语英语词典

Note:

  • Some words have a lot of translation that may occupy the entire screen.

Translate the word in clipboard

Using -c/--clipboard to translate the word in clipboard:

$ dict-tiny -c
命令行  
======
command line

You can use both -g and -c.

$ dict-tiny -g -c
>>> Google Translate
input: clipboard
output: 剪贴板
detected language: en

Note:

  • Adding -c and -m at the same time, which means get more detail translation about the word in clipboard.

  • -c/--clipboard has low priority. If you add -c and a word at the same time, the switch -c will be ignored.

License

MIT

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

dict-tiny-1.1.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

dict_tiny-1.1.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file dict-tiny-1.1.3.tar.gz.

File metadata

  • Download URL: dict-tiny-1.1.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for dict-tiny-1.1.3.tar.gz
Algorithm Hash digest
SHA256 de46f836863b3426fa61c5a1274ceb19266a4b88d0a99dcfc96f1ba597dd4a23
MD5 3f3a3397fd8a2d0987d6c17e4781a962
BLAKE2b-256 d2f369e53a2811bc1a1fd9059f455a9fea7de61c9a974323abef8c0ae507e15d

See more details on using hashes here.

File details

Details for the file dict_tiny-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: dict_tiny-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for dict_tiny-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eac3d094a54935eabe4256a31cddfcab010ef93677fe8266b6594ec5c7e60be7
MD5 991e0741d5b71834b9691e41fa579b1d
BLAKE2b-256 12211a6fcfef91911854416bae31cbf204a41eef2e7469ccb69a9d093dfe8acc

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