Skip to main content

A command-line tool that integrates Youdao Dict and Google Translate.

Project description

Dict-tiny

PyPI version GitHub Workflow Status License: MIT Downloads

A command-line tool that integrates Youdao Dict and Google Translate.

Just for fun :)

Features

  • Youdao dictionary
  • Google Translate
  • Interactive mode with word auto-completion

demo_2_0_0

Installing

Install with pip. (Python >= 3.9)

$ pip install dict-tiny

Upgrading

$ pip install --upgrade dict-tiny

Options

$ dict-tiny

Usage:
    dict-tiny [SWITCHES] words...

GoogleTranslate:
    --detect-language                   Detect the language of the given text
    -g, --google                        Use Google Translate

Meta-switches:
    -h, --help                          Prints this help message and quits
    --help-all                          Prints help messages of all sub-commands and quits
    -v, --version                       Prints the program's version and quits

Switches:
    -c, --clipboard                        Use the contents of the clipboard.
    -i, --interactive                      Interactive mode
    --sl, --source-language VALUE:str      Source language (YoudaoDict only supports en/fr/ja/ko)
    --tl, --target-language VALUE:str      Target language (YoudaoDict only supports en/fr/ja/ko)

YoudaoDict:
    -m, --more                             Get more details
    -y, --youdao                           Use Youdao Dictionary to translate

Details and examples

Youdao Dict

Add -y / --youdao to use Youdao Dict:

Youdao only supports Chinese↔English, Chinese↔French, Chinese↔Japanese, and Chinese↔Korean translation. The default is Chinese↔English.

--source-language / --target-language only accept the following codes:

Code Language
en English
fr French
ja Japanese
ko Korean

Chinese is the implicit counterpart — no need to specify zh. For example, Chinese↔Japanese requires --target-language ja or --source-language ja.

$ dict-tiny -y book

>>> YoudaoDict <<<
book
======
[]bʊk []bʊk

n. 书,书籍;本子,簿册;(长篇作品的)篇,卷,部;装订成册之物;赌局,打赌;账册,账簿
v. 预订,预约;(警方)将……记录在案;(裁判)记名警告
 【名】 (Book)(英)布克,(瑞典)博克,(朝)北(人名)
复数: books, 第三人称单数: books, 现在分词: booking, 过去式: booked, 过去分词: booked
$ dict-tiny -y 书

>>> YoudaoDict <<<

===
shū

book
书,书籍;本子,簿册;(长篇作品的)篇,卷,部;装订成册之物;赌局,打赌;账册,账簿;预订,预约;(警方)将……记录在案;(裁判)记名警告;【名】 (Book)(英)布克,(瑞典)博克,(朝)北(人名);

write
写作,编写;写道;写信;书写,写字;谱写(音乐作品);编写(计算机程序);将(计算机中的)数据写入(磁盘或其他储存媒体);填写(表格、支票等),拟定;(笔)能写字;拼写;<加,南非>参加(笔试);书写,手写(与铅印相对);以写作为生;承保(保险单);

letter
信,信函;字母;<美>(缝制在运动服上的)校运动队首字母标志;<英,非正式>(代表学位或职位等资格的)首字母缩略词(letters);文学;法律文书,正 式文书(letters);字面确切含义;(印刷)一种铅字字体;<古> 学识,渊博的学问;用字母标注;把字母印刷(或缝制等)于;<美>赢得学校运动队的字母标志;【名】 (Letter)(美、英、巴西)莱特(人名);

script
剧本,讲稿;笔迹,手写体;连写体,草体;字体;(一种语言的)字母系统,字母表;<英>(考生的)笔试答卷; 脚本(程序)(计算机的一系列指令);<非正式>(医生的)处方;期待,计划;写剧本,写讲稿;事先准备,计划;

Use -m / --more to get more detailed translations for the word:

$ dict-tiny -y 曾经 -m

>>> YoudaoDict <<<
曾经
====
céng jīng

once
一次, 一回;曾经,一度;任何一次,从来;乘以一;一.....就, 一旦;一次;

ever
曾经,从来,在任何时候;一直,始终;越来越,愈发;究竟,到底;非常,确实;【名】 (Ever)(英)埃弗,(俄)叶韦尔,(西、法)埃韦尔(人名);


📖 《吴光华汉英大辞典》:
once
  He once lived in Shanghai.
  他曾经在上海住过。
  She has taken part in a major battle for oil.
  她曾经参加过石油大会战。
  I have seen him before.
  我曾经见到过他。


📖 《现代汉语规范词典》:
曾经 [céngjīng] (副词)
参见1557页“已经”的提示。

表示从前有过某种动作、行为或情况
  例: 她曾经跳过芭蕾舞
  例: 他十年前曾经去过日本。
$ dict-tiny -y dictionary -m

>>> YoudaoDict <<<
dictionary
============
[]ˈdɪkʃəneri []ˈdɪkʃən(ə)ri

n. 字典,词典;专业词典,术语大全;电子词典;双语词典
复数: dictionaries

📖 collins:
dictionary【ˈdɪkʃənərɪ】

======== 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.
     …一本西班牙语—英语词典。

Specify --target-language to translate to other languages.

$ dict-tiny -y 进击的巨人 --target-language ja

>>> YoudaoDict <<<
进击的巨人
=======
jinjidejuren

進撃の巨人(しんげきのきょじん)(日本漫画家谏山创创作的少年漫画作品,于2009年在讲谈社旗下的漫画杂志《别册少年》上开始连载。)
$ dict-tiny -y Bonjour --source-language fr

>>> YoudaoDict <<<
Bonjour
=========
bɔ̃ʒu:r

[m.]
早安,日安,白天好,你好
$ dict-tiny -y go는 구글이 만든 오픈 소스 프로그래밍 언어이다 --sl ko

>>> YoudaoDict <<<
go는 구글이 만든 오픈 소스 프로그래밍 언어이다
=============================
go是谷歌开发的开源程序设计语言

Google Translate

Add -g / --google to use Google Translate:

$ dict-tiny -g book

>>> GoogleTranslate <<<
book
======
output: 书
detected language: en

Add --target-language to specify the language to translate results into:

$ dict-tiny -g operation system --target-language ja

>>> GoogleTranslate <<<
operation system
==================
output: オペレーションシステム
detected language: en

Add --source-language to specify the source language of the input text. In most cases this is optional, as the Google Translate API automatically detects the source language.

If you specify the wrong source language, the translation result may not be what you expect.

Use --detect-language to detect the language type instead:

$ dict-tiny -g --detect-language español

>>> GoogleTranslate <<<
español
=========
confidence: 0.49805447459220886
input: español
language: es
name: Spanish

Note:

  • Make sure Google services are 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
    
    >>> GoogleTranslate <<<
    book
    ======
    output: source language: en
    

    You can also enter the ISO language name:

    $ dict-tiny -g book --target-language German --source-language English
    
    >>> GoogleTranslate <<<
    book
    ======
    output: Buch
    source language: English
    
  • Set the environment variable $DICT_TINY_TARGET_LAN so you don't have to specify the target language each time. If you also pass --target-language on the command line, it overrides the environment variable.

  • The default target-language is Chinese .

Interactive mode

You can enter interactive mode for any translator by adding -i. Press Ctrl + d to exit.

In interactive mode you can:

  • Continuously query words in an interactive session.
  • Press Tab for word auto-completion (using Youdao's auto-completion function, currently only supports Chinese, English, French, Korean, Japanese)
  • Settings cannot be changed after entering interactive mode, such as target-language or source-language. You need to exit and re-enter to change them.

Other

Default behavior

  • Youdao Dict is the default translator used when no translator is specified.

    $ dict-tiny 机器学习
    
    >>> YoudaoDict <<<
    机器学习
    ======
    machine learning
    

    You can use the environment variable $DICT_TINY_DEFAULT_TRANS to set the default translator. Options: youdaodict or googletranslate.

  • For Youdao Dict and Google Translate, if the target language is not specified, Chinese and English are used as the target language for one another.

  • In non-interactive mode, multiple translators can be used at the same time, for example dict-tiny formulation -y -g.

    $ dict-tiny formulation -y -g
    
    >>> YoudaoDict <<<
    formulation
    =============[ˌfɔːmjuˈleɪʃ(ə)n][ˌfɔːrmjuˈleɪʃ(ə)n]
    n. (政策、计划等的)制定,构想;(想法的)阐述方式,表达方法;(药品或化妆品的)配方,配方产品
    >>> GoogleTranslate <<<
    formulation
    =============
    output: 公式
    detected language: en
    

Use clipboard content

Use -c/--clipboard to use the contents of the clipboard:

$ dict-tiny -c -y

>>> YoudaoDict <<<
encounter
===========[ɪnˈkaʊntə(r)][ɪnˈkaʊntər]
v. 遭遇;偶遇,邂逅
n. 偶遇,邂逅;经历,体验;冲突;比赛,交锋

Note:

  • -c/--clipboard has lower priority than passing a word directly. If you supply both, -c is ignored.

Environment variables

name default description
DICT_TINY_TARGET_LAN Specify the default target language.
DICT_TINY_SOURCE_LAN Specify the default source language.
DICT_TINY_DEFAULT_TRANS youdaodict Specify the default translator.
youdaodict / googletranslate

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-2.0.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dict_tiny-2.0.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file dict_tiny-2.0.0.tar.gz.

File metadata

  • Download URL: dict_tiny-2.0.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dict_tiny-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4ed2835da11f1d219691d358f4f5755d49c3ea3df442df3b5fa9cb540db08228
MD5 0f13ff261fc2dc432054e6d1013e182c
BLAKE2b-256 3382a58a5e43fc18986e49a4bfb09be07f40a630adf4763d377c4e82dd81d80e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dict_tiny-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dict_tiny-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2abd8b7ec4b724a3c261818b8f7232eeffa865c46a08c26868ad0234a1f6db31
MD5 a7dcf29095e96f07d782897732ea2d61
BLAKE2b-256 4525e95dea68230b0a07ddb9a30ca1a8929e58d7dbfb8dacfcb3ee4735dd8dc1

See more details on using hashes here.

Supported by

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