Skip to content

mathewsmachado/tl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tl

CLI working

Being a non-native speaker of English and having to deal with the language every day, especially in coding, I sometimes have to resort to google translate. Doing this many times a day makes it a repetitive task and, to reduce the time I spend doing it, I wanted to create a command-line translator.

Features

Getting Started

Pre-requisites

To make this work, you will need to have git to clone this project, npm to install it, Node.js and a browser installed to run this app.

Downloading the Project

git clone https://github.com/MathewsMachado/tl; \
cd tl

Setting up the Environment Variables

In order for this to work, you'll have to configure the "BROWSER_PATH" constant into the "constants" file before installing it.

Installation

yarn; \ # or "npm install"
yarn install:global # or "npm run install:global"

Usage

After installing it globally, you can call it as in:

tl {{ language to translate }} {{ text to translate }}

Parameters

{{ language to translate }}: The language the text is going to be translated into.

{{ text to translate }}: The text to be translated.

Examples

tl pt how to write a good \"README\" file
tl en como escrever um bom \"README\"

Customization

This CLI is customizable and all the customizable options are inside the "constants" file, the only one you need to modify.

  • BROWSER_PATH: The path to your browser executable. In Linux, the path is under the "bin" folder.

  • MAX_WAITING_TIME_IN_MS: The maximum amount of time you want to wait for the translation result. It accepts any integer value.

  • LANGUAGES: The supported languages are "en", "pt", "es" and "ja".

  • RESULT_COLOR: The supported colors are "black", "red", "green", "yellow", "blue", "magenta", "cyan" and "white".

Observations and Technical Informations

As I haven't found a way to make requests to the same endpoint of google-translator and the API that Google offers needs an account, an API key etc, I decided to make the translation through web-scrapping, so it could be as easy as possible for everyone to use.

To reduce the size of this CLI, as everyone has a browser nowadays, "puppeteer-core" was chosen instead of "puppeteer". The main difference between the two is that "puppeteer-core" doesn't come with chromium — reducing the package size —, making it mandatory for the user to specify their own browser path.

To-do

  1. Increase the number of languages text can be translated into.

Contribution

This project is accepting contributions, the aim is to clean the to-do list.

Feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.