A simple #golang tool to translate text using Azure Translation Services.
Microsoft offers an excellent translation API on Azure than can be used (with limitation) for free that offers more capacity than soimort's translate-shell tool.
I'm a really fan of soimort's translate-shell tool but recently the limits imposed by the free Apis were very limiting. Also, because this tool is written in Golang which is more familiar than AWK.
Microsoft Translator is a cloud-based machine translation service. The core service is the Translator Text API, which powers a number of Microsoft products and services, and is used by thousands of businesses worldwide in their applications and workflows, which allows their content to reach a global audience.
The Translator Text API is easy to integrate in your applications, websites, tools, and solutions. It allows you to add multi-language user experiences in more than 60 languages, and can be used on any hardware platform with any operating system for text-to-text language translation.
The Translator Text API is part of the Azure Cognitive Services API collection of machine learning and AI algorithms in the cloud, and is readily consumable in your development projects
Azure's Cognitive Api provides up to 2M chars of standard translation per month which should be more than enough for regular users.
This tool requires an Azure Account. Creating an account in Azure is free and can be done at https://azure.microsoft.com/free/.
This document describes how to create a Cognitive Api Key on Azure.
Assuming you have Go installed, you can use go get
(if you're using Go 1.7 or newer):
go get -u github.com/hd9/gotrans
Make sure the ~/go/bin
path is present in your $PATH
env var with:
PATH=$PATH:~/go/bin
Then run gotrans
with:
gotrans -h
The tool can be used from the command line and accepts redirections and files as inputs.
-------------------------------------------------------
gotrans - Translate text using Azure Cognitive Services
-------------------------------------------------------
Usage:
./gotrans -t nl "<text-to-translate>"
./gotrans -t es -file <file>
echo "text" | gotrans [OPTIONS]
cat <file> | gotrans [OPTIONS]
Options:
-h, --help
Show help
- string
Text to translate
-f string
Source Language (optional). Set empty to auto-detect
-file string
File name
-t string
Target language. See list here: https://bit.ly/37o3PFX
-v Run in verbose mode
The tool can also be called from inside Vim. Simply select some
text in visual mode and, assuming it's available on your $PATH
, run:
'<,'> !gotrans -t es
This is alpha software and was developed in less than one day to cover my specific needs so expect bugs. Feel free to open an issue and contribute.
Thanks!
- What is the Translator Text API?
- Translator Text API 3.0
- Translator Text API 3.0: Languages
- Translator Text documentation
- How to sign up for the Translator Text API
- Quickstart: Use the Translator Text API to translate text
- MicrosoftTranslator / Text-Translation-API-V3-Go | GitHub
- Azure Cognitive Services
- translate-shell tool