Go to file
l3n b26e703002 Add no color option (can be set as default variable). 2019-12-30 19:45:02 +01:00
README.org Add no color option (can be set as default variable). 2019-12-30 19:45:02 +01:00
trans.sh Add no color option (can be set as default variable). 2019-12-30 19:45:02 +01:00

README.org

Ponsapi-cli

Introduction

There was no nice command line tool for translations to be found so I've written my own. I was frustrated by opening a new tab in browser whenever I wasn't able to remember a translation of a word. I use terminal a lot and ponsapi-cli is one of the micro optimisations that at the end of the day sum up (I hope).

I gave a lot of attention to pretty printing results, but not so much care was spent to make the translation script fast. It is something that will be addressed in the future versions but until then all you get is "pretty printing".

Usage

trans [flags] <word>

To get help use flag -h.

-f option (fuzzy matching) helps if no results were found.

Dependencies

This script uses following tools:

  • curl
  • jq
  • recode
  • sed

Installation

First you have to register at pons.com api registration form.

Once you get your API secret key, create a file named ponsapi.config in one of these paths: $HOME, $HOME/.config or $HOME/.config/ponsapi-cli.

Besides PONS_SECRET="<your-pons-secret>" line in your config file, you can specify other default parameters there as well (PONS_DICT for dictionary - you can see a list of those by calling trans script with flag -o and PONS_LANG to specify in which language is the word you are looking translation for).

Make your script executable and crate a symlink to it in your execution path. Simplier solution is to just a create alias in your .bashrc/.zshrc file (alias trans="<path-to-script>/trans.sh")

How it works

Script creates a curl request to pons api and parses json response with jq. Json response can have 2 different structures depending on a results found in their dictionary. This complicates parsing a little bit but script has two functions written for parsing each of those two different structures and creates a unified json which is then used for pretty printing results.

You can see raw results with -r flag.

Development

I will rewrite this application in haskell once I found more time. Even before that I'll implement some error handling.

to do

  • error handling
  • rewrite into haskell

done

  • no color option