Skip to main content

A tiny command-line dictionary and translator implemented in Plumbum. Youdao.com and Google Translation API. Just for fun :)

Project description

Dict-tiny

PyPI version GitHub Workflow Status License: MIT

A command-line utility that can be used as:

  • A dictionary of Chinese and English word translation by getting the data of youdao.com.
  • A translator by using Google Translation API. It can alse be used to detect language type.

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

One word

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

Getting more detail

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

$ 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:

  • Adding -c and -m at the same time, which means get more detail translation about the word in clipboard.
  • Some words have a lot of translation that may occupy the entire screen.

Using Google Translation API

Adding -g to use Google Translation API:

$ dict-tiny -g book
detectedSourceLanguage: en
input: book
translatedText: 

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

$ dict-tiny -g book --target-language japanese
detectedSourceLanguage: en
input: book
translatedText: 

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
confidence: 1
input: book
language: en
name: English

Note:

  • 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.

  • If your input is a sentence or more than one word, the Google Translation API will be called automatically. In other word, you don't need to manually add -g when you type a sentence.

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

    $ dict-tiny -g book --target-language zh --source-language en
    input: book
    translatedText: 

    You can also enter the ISO language name:

    $ dict-tiny -g book --target-language chinese --source-language english
    input: book
    translatedText: 
  • The default target-language is ENGLISH_ISO_639='en' 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. (If the input is also English then the default target-language will be Chinese.)

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
detectedSourceLanguage: en
input: clipboard
translatedText: 剪贴板

Note:

  • -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.0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

dict_tiny-1.0.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dict-tiny-1.0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for dict-tiny-1.0.1.tar.gz
Algorithm Hash digest
SHA256 83c3e252a08814e3284b264cf3474ce952c423f8081d5406a2a2ea96298eff5e
MD5 86ac77acc53184b7567a246eca5a3e7c
BLAKE2b-256 8233c0814760a381cd4eac392f923a49fe5df2b74d83907829df8d7e47de0acf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dict_tiny-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for dict_tiny-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 139b7075667861a9322962ab60026104f669ce880478b5ae576f18024ccc33cd
MD5 3042a58d68a0467952f2265e2bdd8bc2
BLAKE2b-256 6f57f75c9c5899f3ecf35f26053a8564872f50feb481c7a79ca86fecb4fb248d

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