19.4 aztranslate translate

20210524 The translate command will detect the source language and translate it to another specified language. It allows a sentence to be translated from/to different languages. The sentence can be part of the command line, piped into the command, or read from file. The source language is automatically identified. The target language can be specified on the command line and defaults to English (en).

$ ml translate aztranslate [options] [sentence]
     -i <file.txt> --input=<file.txt>   Input text file to translate.
     -t <lang>     --to=<lang>          The target language (default *en*), e.g., fr.

Language codes include hi for Hindi, fa for Fairsi, fr for French, and id for Indonesian. See supported for a full list of supported languages.

The output is in a form that can be readily piped to other commands, in a comma separate value (CSV) format. The fields, separate by commas, begin with the identified input language and then the confidence of the model that it has correctly identified the language. This is on a scale from 0 to 1, with 1 representing 100% confidence. The next field records the output language. The remainder of the output is the text translated to the target language (which might include further commas within it, but they are not field separators in this case).

In the first example below we have a sentence in French (which is correctly identified as fr with 100% confidence) translated to English (en). The second example is Indonesian (id) translated to English.

$ ml translate aztranslate C’est l’exception qui confirme la règle.
fr,1.0,en,This is the exception that confirms the rule.

$ ml translate aztranslate Dimana ada kemauan, di situ ada jalan
id,1.0,en,Where there is a will, there is a way

We can choose the language to translate to, as in this next example where we translate from French (identified as fr and 100% certainty), to Vietnamese using the option --to=vi. The vi is the standard code for Vietnamese.

$ ml translate aztranslate --to=vi C’est l’exception qui confirme la règle.
fr,1.0,vi,"Đó là ngoại lệ xác nhận quy tắc.

If the text to be translated is in a file then we can request the whole file to be translated.

$ ml translate aztranslate --input=mydoc.txt
zh-Hant,1.0,en,Due to the COVID-19 National Emergency, the EPA is now
taking action to keep our staff healthy and safe and implement
contingency plans to ensure that our responsibilities are carried out.

If no arguments are supplied then an interactive loop is activated, so simply enter text. It is sent off for translation when you press Enter. Multiple lines are allowed so finish with Control-D.

$ ml translate aztranslate
Un'enciclopedia libera e multilingue.
it,1.0,en,A free and multilingual encyclopedia.

Ctrl-D


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.