Is it possible to translate words via terminal?
For offline use:
You can install dictd
server and use Freedict Dictionary database for word translations.
Install dictd:
sudo apt-get install 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
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?"
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
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:
-
Using a particular database (eg. WordNet - wn):
dict -d wn "dictionary"
-
Not specifying a dict-database will output definitions/translations/thesaurus from all available databases. eg.
dict "dictionary"
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
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.