huhx / go_translator

Translation tools using Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A command line tool that translate chinese to english and vice versa, it also provides the feature of querying the translation history.

Right now, it only supports the English and Chinese languages.

Background

When I want to translate words between chinese and english, using the Google translation web page I need to choose the source and target language. It is less convenient to me. So I decide to develop a command line tool that simplify the translation work since it can identify the language automatically.

Implementation

  • cobra: the core of the command line
  • viper: store the translation api key and secret
  • http: use to call translation api

Features

  • Translation:
trans "I love coding" # 我喜欢编码
trans 我喜欢游泳 # I like swimming
  • History record
trans -l

#                                 Query|                      Result|CreateTime
#                                  ----|                         ---|-------
#   Chinese people are very intelligent|                     **人非常聪明|2024-04-18 17:02:10
#                              我们的爱从未消失|   Our love never disappears|2024-04-18 17:04:12
#            make the world much better|                    让世界变得更美好|2024-04-18 17:04:30
  • Clean up history record
trans -c # successfully cleared

Deploy

prepare the viper configuration file: ~/.go_translator.yaml

appId: "{baidu_app_id}"
appSecret: "{baidu_app_secret}"
fileName: "go_translator_record.csv

https://fanyi-api.baidu.com/manage/developer

build the exec command

go build -o trans main.go
go install trans

# or
make deploy

About

Translation tools using Go

License:Apache License 2.0


Languages

Language:Go 99.3%Language:Makefile 0.7%