34

I would like to translate words from English to Language X trough terminal

  • If it is possible, what kind of dictionaries there are?

  • Is it possible to use online services like webxicon.org trough terminal?

1

9 Answers 9

36

For offline use:

You can install dictd server and use Freedict Dictionary database for word translations.

Install dictd:

sudo apt-get install dictd

dictd

Install translation database. eg. dict-freedict-eng-fra for English to French translation, dict-freedict-eng-spa for English to Spanish translation.

sudo apt-get install dict-freedict-eng-fra
sudo apt-get install dict-freedict-eng-spa

freedictDB

Usage:

View list of databases:

dict -D

Use a particular database eg. for English to Spanish translation:

dict -d fd-eng-spa "how are you?"

snapHowRU

For online use:

Install libtranslate-bin with:

sudo apt-get install libtranslate-bin

eg. using online google translate engine:

echo "what are you doing" | translate-bin -s google -f en -t fr

onlineGoogleTranslate


Offline English dictionary in Terminal:

Installing English dictionary databeses (gcide, wn, devil):

sudo apt-get install dict-gcide
sudo apt-get install dict-wn
sudo apt-get install dict-devil

Installing English Thesaurus database (moby-thesaurus):

sudo apt-get install dict-moby-thesaurus

Usage:

  1. Using a particular database (eg. WordNet - wn):

    dict -d wn "dictionary"
    
  2. Not specifying a dict-database will output definitions/translations/thesaurus from all available databases. eg.

    dict "dictionary"
    
6
  • Is there a eng-eng dictionary?
    – user224082
    Dec 24, 2013 at 20:26
  • 1
    @DuminduMahawela: ... there are... I've updated my post including a few of them... hope you'll like them...
    – rusty
    Dec 25, 2013 at 3:59
  • 1
    Thanks. I was searching some period for a terminal eng-eng dictionatry. You have done good job.
    – user224082
    Dec 25, 2013 at 4:02
  • No definitions found for "how are you?"
    – abc
    Oct 6, 2018 at 2:41
  • does not work . thumb down
    – abc
    Oct 6, 2018 at 2:52
14

Translate Shell

Translate Shell (ex Google Translate CLI) is a tool that lets you use translate text from the command line using Google Translate.

Installation

$ wget git.io/trans
$ chmod +x ./trans

Or

sudo apt install translate-shell

Or

$ git clone https://github.com/soimort/translate-shell
$ cd translate-shell/
$ make
$ [sudo] make install

Usage

To translate

trans en:de "The quick brown fox jumps over the lazy dog"  # Translate to German (de)
trans es: "Igualdad, fraternidad y libertad"  # From Spanish to your `locale`
trans :fr "Igualdad, fraternidad y libertad"  # From your `locale` to French
trans -b :fr "Igualdad, fraternidad y libertad"  # Same but `-brief`

As a dictionary: Google Translate can be used as a dictionary when lang from==to or -d parameter is used

trans -d fr: mot

Additional information and some examples can be found in the official site

3
  • make: *** No rule to make target 'install'. Stop.
    – abc
    Oct 6, 2018 at 2:44
  • wget github.com/soimort/google-translate-cli/archive/master.tar.gz && tar -xvf master.tar.gz && cd translate-shell-master && sudo make install && trs "some text" && trs {en=afr} "TEXT TO TRANSLATE"
    – abc
    Oct 6, 2018 at 2:50
  • does not work , thumb down
    – abc
    Oct 6, 2018 at 2:51
6

Depending on the language you want, check out Apertium for offline machine translation through the terminal. It seems to focus mostly on Romance languages (ES, FR, PT, CAT, OCC..), but looks like they are slowly adding various new languages.

For Spanish you would install:

sudo apt install apertium apertium-en-es

echo "Hola Mundo." | apertium -a es-en
> Hello world.

It's terminal based but there's also a basic GUI: apertium-tolk

The version in the repos is older, if you want a newer version follow the install instructions.

3

Argos Translate (offline, open source, Pytorch-based, text translation)

GitHub repository: https://github.com/argosopentech/argos-translate

Docs: https://argos-translate.readthedocs.io/en/latest/source/cli.html

On Ubuntu 23.10 you need:

sudo apt install pipx
pipx install argostranslate==1.9.1

This takes up about 5 GB of disk space, ncdu tells me:

--- /home/ciro/.local/pipx/venvs ----------
                                          /..                                                                                                                                                 
    4.7 GiB [#########################  ] /argostranslate

Install the English to French model from the CLI:

argospm install translate-en_fr

Each model is unidirectional (i.e. e.g. either English to French or French to English) and about 80 - 110 MB in size packed. They are hosted at: https://drive.google.com/drive/folders/11wxM3Ze7NCgOk_tdtRjwet10DmtvFu3i Locally they end up e.g. at ~/.local/share/argos-translate/packages/translate-en_fr-1_9.

Minimal CLI example:

argos-translate --from-lang en --to-lang fr "I like to eat cheese."

Output:

J'aime manger du fromage.

Parfait!

There is also a GUI which is cute but a bit useless, and takes up another 5 GB of disk space:

argos-translate-gui
pipx install argostranslategui==1.6.5

enter image description here

Now, let's try to have some actual fun by trying to translate the entirety of Pride and Prejudice to French:

wget -O pap.txt https://www.gutenberg.org/cache/epub/1342/pg1342.txt

How many words:

wc pap.txt

~130k:

14911 130408 772448 pap.txt

so let's translate ~1/15th of the text:

head -n1000 pap.txt | time argos-translate --from-lang en --to-lang fr > pap-fr.txt

Stats on my Lenovo ThinkPad P14s gen4 amd:

207.09user 3.61system 0:48.77elapsed 432%CPU (0avgtext+0avgdata 612716maxresident)k
0inputs+88outputs (14major+609013minor)pagefaults 0swaps

Let's try the whole thing to see if it scales in memory:

cat pap.txt | time argos-translate --from-lang en --to-lang fr > pap-fr.txt

and yes, it's fine:

523.95user 24.47system 13:28.26elapsed 439%CPU (0avgtext+0avgdata 699820maxresident)k
0inputs+1568outputs (14major+757996minor)pagefaults 0swaps

As per the documentation, GPU acceleration is turned off by default, so all of that happened on the CPU. It should be possible to enable it with the ARGOS_DEVICE_TYPE=cuda environment variable as in:

ARGOS_DEVICE_TYPE=cuda argos-translate ...

but I have not yet been able to benchmark this on a GPU.

Let's see the quality, the start:

It is a truth universally acknowledged, that a single man in possession
of a good fortune must be in want of a wife.

However little known the feelings or views of such a man may be on his
first entering a neighbourhood, this truth is so well fixed in the minds
of the surrounding families, that he is considered as the rightful
property of some one or other of their daughters.

“My dear Mr. Bennet,” said his lady to him one day, “have you heard that
Netherfield Park is let at last?”

Mr. Bennet replied that he had not.

“But it is,” returned she; “for Mrs. Long has just been here, and she
told me all about it.”

Mr. Bennet made no answer.

went to:

C'est une vérité universellement reconnue, qu'un seul homme en possession
d'une bonne fortune doit être en manque d'une femme.

Si peu connus que soient les sentiments ou les opinions d'un tel homme,
d'abord entrer dans un quartier, cette vérité est si bien fixée dans les esprits
des familles environnantes, qu'il est considéré comme le juste
propriété de l'une ou l'autre de leurs filles.

"Mon cher M. Bennet," lui a dit sa dame un jour,
On laisse enfin Netherfield Park ? C'est-à-dire

M. Bennet a répondu qu'il ne l'avait pas fait.

Mais elle est revenue, car Mme Long vient d'être ici, et elle
m'a tout raconté. C'est-à-dire

M. Bennet n'a pas répondu.

And Google Translate for reference:

C'est une vérité universellement reconnue qu'un seul homme en possession
celui qui a de la chance doit avoir besoin d'une femme.

Si peu connus que soient les sentiments ou les opinions d'un tel homme à son arrivée dans un quartier, cette vérité est si bien ancrée dans l'esprit des familles environnantes, qu'il est considéré comme l'homme légitime.
propriété de l'une ou l'autre de leurs filles.

« Mon cher M. Bennet, lui dit un jour sa dame, avez-vous entendu dire que
Netherfield Park est enfin loué ?

M. Bennet a répondu que non.

«Mais c'est vrai», répondit-elle; "car Mme Long vient d'arriver ici, et elle
m'a tout raconté.

M. Bennet ne répondit rien.

So:

  • "fortune": Argos does better than Google Translate, as fortune actually means fortune here, not luck
  • "d'abord entrer dans un quartier": bad grammar and collocation, Google wins
  • "On laisse enfin Netherfield Park ?": translated let as "leave" rather than "letting". Google Translate does correctly. Should be inferrable from nearby context.
  • "C'est-à-dire": noise 2x?
  • "M. Bennet a répondu qu'il ne l'avait pas fait.": he didn't do anything, Google wins
  • "Mais elle est revenue": return translated as "return" rather than reply. Google Translate wins.

So Argos put up a reasonable fight, but Google Translate was basically strictly better. Some of it was luck, and some was perhaps due to the slight age of the text. But a large part was because Google Translate is curreently better.

Case Study: Xin Yue letter

Now for a more realistic test from: https://github.com/sikaozhe1997/Xin-Yue Here's some context. The letter should be in very correct and direct Chinese.

I tried to paste the text into a file and then:

argos-translate-cli --from-lang zh --to-lang en $(cat input.txt)

but it didn't work very well. They don't seem to have a method to take input from a file currently, but Command Line is marked as "Beta", so give them some slack.

So the translation below is from the GUI. I fixed the formatting a little bit, but the text is unchanged.

Chinese original:

在此,我正式向北京大学外国语学院提出以下诉求:

  1. 北京大学外国语学院应公开书面说明越过我向家长施压、凌晨到宿舍强行约谈我、要求我删除申请信息公开一事的相关资料所依据的规章制度,对此过程中违法违规操作予以明确,并采取措施避免此类事件再次发生。
  2. 北京大学外国语学院应立即停止一切对我家人的施压行为,向我已经遭受惊吓的母亲正式道歉并澄清事实,帮助修复因此事导致的家庭紧张关系。
  3. 北京大学外国语学院必须公开书面保证此事不会对本人毕业一事产生影响,并不会再就此事继续干扰我的论文写作进程。
  4. 北京大学外国语学院负责消除此事对本人学业、未来就业和家人的其他一切不良影响。
  5. 北京大学外国语学院应明确就以上诉求进行公开书面回复,给关注此事的大家一个交代。

我将保留通过法律手段进一步追究相关个人和单位责任的一切权利,包括但不限于向北京大学和上级主管部门举报外国语学院严重违反校纪的行为。

北京大学外国语学院14级本科生岳昕

Argos Translation:

Here, I formally put forward the following claims to the Foreign Language Institute of the University of Beijing:

  1. The Foreign Language Institute of the University of Beijing should make a public written statement of the regulatory framework under which I have imposed pressure on parents, entered the house and asked me to remove the information on the application for disclosure of information, and to make clear that violations of the law are committed and to take measures to avoid the recurrence of such incidents.
  2. The Foreign Language Institute of the University of Beijing should immediately stop all pressure on my family, formally tunnelling and clarifying the facts to the mother who has been threatened and helping to restore the family tensions that have resulted from the events.
  3. The Foreign Language Institute of the University of Beijing must publicly and in writing ensure that the matter does not have an impact on his graduation and will not continue to interfere with the process of writing my paper on the matter.
  4. The Foreign Language Institute of the University of Beijing is responsible for eliminating any other negative impact of this matter on his own education, future employment and family.
  5. The Beijing University College of Foreign Languages should provide a clear written response to the above claims and give a voice to all those concerned.

I will retain all the rights to further pursue the responsibility of the individuals and units concerned through legal means, including, but not limited to, reporting to the Beijing University and the superior authorities of serious violations of the discipline of foreign languages.

University of Beijing Foreign Language College, 14th class Bachelor

Manual (TODO confirm) translation:

Hereby I formally request the following from the School of Foreign Languages of Peking University:

  1. The School of Foreign Languages of Peking University should formally and publicly state the regulations, in accordance to which they pressured my parent without my knowledge, abruptly interviewed me in my dorm 1am in the morning and asked me to delete information related to the FOI request. Specify the illicit practices and put forward actions to prevent this from happening again.
  2. The School of Foreign Languages of Peking University should immediately stop any action of pressuring my families, formally apologize and clarify the facts to my frightened mother, and help to repair the family relationship intensified by this incident
  3. The School of Foreign Languages of Peking University must make a formal promise that this incident will not affect my graduation and will not disturb my Thesis preparation in the future.
  4. The School of Foreign Languages of Peking University is responsible to eliminate all other negative effects to my study, future employment and family, caused by this incident.
  5. The School of Foreign Languages of Peking University should publicly give a written response to the above appeals, as an explanation to those who are concerned about this matter.

I reserve the right to pursue legal actions against related individuals and organizations, including, but not limited to, reporting to the Peking University and superior administrations the severe violation of the Code of Conducts made by the School of Foreign Languages.

Undergraduate student Yue Xin, Class 2018 at the School of Foreign Languages of Peking University

Google Translate:

Here, I formally make the following demands to the School of Foreign Languages ​​of Peking University:

  1. The School of Foreign Languages of Peking University should publicly explain in writing that it has gone beyond me to pressure my parents, went to the dormitory to interview me in the early morning, and asked me to delete the relevant information related to the information disclosure application. The rules and regulations shall be clarified. Take measures to prevent such incidents from happening again.
  2. The School of Foreign Languages of Peking University should immediately stop all acts of pressure on my family, formally apologize and clarify the facts to my mother who has been frightened, and help repair the family tension caused by the incident.
  3. The School of Foreign Languages of Peking University must publicly ensure that this matter will not affect my graduation, and will not continue to interfere with my thesis writing process.
  4. The School of Foreign Languages at Peking University is responsible for eliminating all other adverse effects of this incident on my studies, future employment and family members.
  5. The School of Foreign Languages of Peking University should clearly respond in written form to the appeal request and give everyone who is concerned about this matter.

I will reserve all rights to further pursue the responsibilities of relevant individuals and units through legal means, including but not limited to reporting serious violations of school discipline by the School of Foreign Languages ​​to Peking University and higher authorities.

Yue Xin, a 14-level undergraduate student, Peking University School of Foreign Languages

So we see that the Google Translate one is a bit better still. But there's promise in this project anyways!

Tested on Ubuntu 20.10, argostranslate==1.0.6.

Argos implementation details

https://argos-translate.readthedocs.io/en/latest/ documents:

Argos Translate uses OpenNMT for translations, SentencePiece for tokenization, Stanza for sentence boundary detection, and PyQt for GUI.

OpenNMT in turn is a deep learning based translator with implementation in both Pytorch and Tensorflow: https://opennmt.net/

LibreTranslate

https://github.com/LibreTranslate/LibreTranslate

Apparently a server built on top of Argos?

Doesn't seem to be very useful for single users, but the point of this is likely to be able to self-host a Google Translate-like translation server/webpage internally for a company, without making everyone setup Argos individually on their machines.

Also it is interesting to note how the higher level the project the more stars it gets!

enter image description here

1
  • 1
    This should be the top answer in 2023 Apr 24, 2023 at 9:17
2

I wrote a simple command-line translator base on google translate using Python.

The code: The python code is less than 100 lines, and I also wrote an installer script, and provide a config file so that could set your default preferred language.

It's under MIT license.

Pre-requisites: Python2.x on Linux, is all it needs, it don't support python3 yet, I might fix this later.

1

Have a look at sdcv based answer here (It also has "Xlanguage" to "Ylanguage" dictionaries):

Is there an offline command-line dictionary?

Should also check surfraw. Once you install, you may get meaning of a word through sr webster difficultWord. One way to translate will be through sr google difficultword in hindi.There will probably be other options for translation as well.

1

Translate "life" to portuguese. Example bellow: (lynx must be installed)

lynx -source 'http://translate.google.com/translate_t?langpair=en|pt&text='life |awk {'print $852'} | cut -d = -f5 |cut -d ';' -f1 |awk 'NF>0'

Where, "en" is english and "pt" is portuguese

Output:
'vida'

0

I have written a simple command-line translator based on text files. It also reproduces an audio file if it exists. I already have a database of audio files, and if I don't find them, then I download them from a google database.

0

There's also a command line interface to dict.leo.org, which provides translation between German and English/Spanish/French/Russian/Portuguese/Polish/Chinese. On ubuntu, the package is called libwww-dict-leo-org-perl.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .