Home
Toloko is a command line tool for translating words. It pretty prints the results in the terminal, and it can also export the results to serialized data formats.
- Project Status
- Introduction
- Platform
- Installation
- Usage
- Resources
- Gratitude
- Extras
- Completion
- Configuration
- Engine
- Frequently (or Never) Asked Questions
- Features
- Formats
- Glosbe
- Hablaa
- New APIs
- Yandex
iloa command: completion, comp
Run toloko comp >> ~/.bashrc
, then source ~/.bashrc
to enable shell completion for toloko commands and options.
To Zsh read your bash script, add to ~/.zshrc
:
autoload bashcompinit
bashcompinit
Now run toloko comp >> ~/.zshrc
and source ~/.zshrc
.
Toloko can get and set values in the configuration file once it's been initialized. Toloko uses the dot-prop library to allow dot notation for nested values. See the FAQ for why I chose noon for the configuration file format.
Toloko command: config
Toloko subcommands:
- init, i - Creates configuration file in home directory (~/.iloa.noon)
- get, g - Gets a value for a given key. Accepts dot notation for nested values.
- set, s - Sets a given key to a given value. Accepts dot notation for nested values.
For globals like verbose
you can just do toloko config set verbose true
. For nested properties, use dot notation like so:
$ toloko config get glosbe.translate.author
Option glosbe.translate.author is true.
$ toloko config set glosbe.translate.author true
Set option glosbe.translate.author to true.
By default, the merge option is set to true, so CLI flags will be merged with the configuration from file. If you pass -s|--save with this, the config file will be overwritten with the current flags. If merge is set to false, the config file will always be used and --save won't work. To restore all defaults run toloko config init --force
.
Refer to the noon syntax guide. When editing the configuration file manually, please remember that empty strings are denoted by two pipes: || and 2 or more spaces separate keys from values.
- chalk and yargonaut are used to style the terminal output.
- good-guy-http gets and caches HTTP requests.
- yargs is used for creating the CLI.
- xml2js is used for XML format, and noon is used for all other formats.
noon, or 'nother ordinary object notation, is a human-readable data format created by monsterkodi. Despite noon being very new, I decided to use it for Leximaven's configuration file because it is incredibly terse, even more so than hjson and cson. This is me supporting a young project that I would like to see get wider recognition. It also makes it dead simple to load and save cson, json, plist, and yaml.
- Extensible
- Configuration file in your home directory called
.toloko.noon
- Access configuration settings by passing commands, setting flags, or just editing the configuration file manually
- Sensible command line defaults and aliases
- XML parsing and building with xml2js
- good-guy-http client with in-memory caching and other neat features. Under the hood is request.
- Save data to CSON, JSON, noon, Plist, XML, and YAML
- Translations and examples from Glosbe
- Translations from Hablaa
- Translations and language detection from Yandex
Toloko supports the following file formats:
- noon - Whitespace-sensitive terse data format created by @monsterkodi, here used for the configuration and theme systems. See FAQ.
- Plain JSON
- Plain XML
- CSON - JSON for Coffeescript objects
- Plist - OSX/iOS data format
- YAML - Human Readable data format
From glosbe.com:
Glosbe provides free dictionaries for almost every existing language and translation memory with over a billion sentences included.
- Almost every live language.
- Huge dictionary database.
- Millions of examples.
- Unique phrases and expressions.
- All Dictionaries
- All Languages
- Transliteration
Toloko command: glosbe, gl
Glosbe subcommands:
- example, ex - Provides translation examples containing a word
- translate, trans, tr - Translates a word
From hablaa.com:
Hablaa provides free translations from and into more than 160 languages.
Toloko command: hablaa, ha
Hablaa subcommands:
- list, langs, ls - Lists supported languages
- translate, trans, tr - Translates a word
Adding new APIs to iloa is pretty straightforward. Look at the docs for yargs to understand the module format. As an example, here's Hablaa's translate module.
Each module registers a command with yargs. The command string defines the command and arguments. The builder object defines our options. The handler function contains our command logic.
After configuration checks and theme loading, we assemble the URL from the parsed arguments, argv
. good-guy-http
fetches the JSON response. For each piece of data that is printed in the console, the same data is added to the tofile
object. If --out
is specified, this object is passed to tools.outFile
which is then encoded and saved. Finally, if --save
is specified, options are saved to configuration.
The Yandex.Translate API is a universal text translation tool that uses machine translation technology developed at Yandex. It allows developers to integrate machine translation into their applications, services, and sites. Translation is currently available for more than 80 languages.
Developers of small translation projects, which do not exceed 10,000,000 characters a month (and no more than 1,000,000 in 24 hours), can use the Yandex.Translate API for free.
Toloko command: yandex, yx
Yandex subcommands:
- detect, dt - Detects the language being used
- list, langs, ls - Lists the supported languages
- translate, tr - Translates a word