Skip to content

Translate text with Amazon Translate and Google Translation.

License

Notifications You must be signed in to change notification settings

takakd/translation-api

Repository files navigation

Translation gRPC API

Translate text with Amazon Translate and Google Translation.

License-MIT 


Table of Contents

Features

  • Translate text with Google Translation API and Amazon Translate API.

Setup

Create AWS and GCP account

This API uses AWS IAM and GCP service account to use each translation API.

For instructions on how to create an AWS account, see Creating an IAM user in your AWS account .

For a GCP account, see Creating and managing service accounts.

Prepare a TLS certificate

Create a server key file and TLS certificate if an API uses TLS.

e.g., Self-signed certificate

$ cd manifest/api/secret
$ openssl genrsa -aes256 -passout pass:gsahdg -out server.pass.key 4096
$ openssl rsa -passin pass:gsahdg -in server.pass.key -out server.key
$ rm server.pass.key
$ openssl req -new -key server.key -out server.csr
...
$ openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

Ref. Generate private key and certificate signing request

Set environment variables

Need Several environment variables.

For details, see .env.example.

Deployment

Several examples are here.

Development

Tech stacks

  • Golang
  • gRPC
  • Kubernetes

Requirements

  • Golang: 1.14.4 darwin/amd64
  • Docker: 20.10.2
  • AWS IAM credentials, which can use Amazon Translate.
  • Google service account, which can use Google Translation API.

We tested in the above environment.

Setup

  1. Install Golang by following Download and install.
  2. Run go mod vendor to get modules.

Helper command

make

Build

$ make build

go test

Run test with details: "-v" and "-cover"

$ make test

Format sources

Run "go fmt", "goimports", and "go lint".

$ make fmt

On local

$ ./scripts/local.sh
Usage:
  ./scripts/local.sh Command

Example.
  ./scripts/local.sh build

Command:
  run           Run envoy and gRPC server on local.
  run:go        Run gRPC server on local.
  run:envoy     Run envoy on local.
  down:envoy    Stop envoy on local.
  grpc          Generate gRPC codes.

Structure

Design

Design

Sources

.
|-- Makefile            <-- Defines make command targets
|-- README.layout.md    <-- golang-standards/project-layout README
|-- README.md           <-- This instruction file
|-- cmd
|   `-- api
|       |-- .env.local      <-- Environment variables on local
|       |-- .env.example    <-- Environment variables example
|       |-- api             <-- This API binary
|       `-- api.go          <-- main func
|
|-- deployments
|   |-- docker-image            <-- Working directory for a container image
|   |-- eks                     <-- EKS deployment examples
|   |-- gcp                     <-- GKE deployment examples
|   `-- local                   <-- Example running on local
|
|-- internal
|   |-- app                     <-- This api directory
|   |   |-- controller          <-- Controller layer
|   |   |   `-- translator      <-- gRPC handler
|   |   |       `-- ...
|   |   |-- driver              <-- Driver layer
|   |   |   |-- aws             <-- Codes related to handling AWS translate service
|   |   |   |   `-- ...
|   |   |   |-- config          <-- Concrete implementation of Config methods
|   |   |   |   `-- ...
|   |   |   |
|   |   |   |-- google          <-- Codes related to handling Google Translation API.
|   |   |   |   `-- ...
|   |   |   |-- grpcserver      <-- gRPC server
|   |   |   |   `-- ...
|   |   |   `-- log             <-- Concrete implementation of Logger methods
|   |   |       `-- ...
|   |   |-- grpc                <-- Auto generated gRPC codes
|   |   |   `-- translator
|   |   |       |-- translator.proto    <-- gRPC service definition
|   |   |       `-- ...
|   |   |-- initializer.go      <-- App initializer func
|   |   `-- util                <-- Codes shared throughout the app
|   |       |-- config          <-- Config
|   |       |   |-- config.go
|   |       |   `-- ...
|   |       |-- di              <-- DI
|   |       |   |-- container   <-- Concrete implementation of DI methods
|   |       |   |   |-- dev
|   |       |   |   `-- ...
|   |       |   |-- di.go
|   |       |   `-- ...
|   |       `-- log             <-- Logging
|   |           |-- log.go
|   |           `-- ...
|   `-- pkg             <-- Codes shared, which are not dependent on the app
|       `-- util        <-- Helper functions
|           |-- file.go
|           |-- http.go
|           |-- time.go
|           `-- type.go
|
`-- scripts             <-- Scripts for this app
    |-- buildimage.sh   <-- For building container image
    |-- local.sh        <-- For local running
    |-- makefile.sh     <-- For Makefile
    `-- mock.pl         <-- To generate go mock file in the same directory

Get in touch

Contributing

Issues and reviews are welcome. Don't hesitate to create issues and PR.

License

© 2021 takakd

About

Translate text with Amazon Translate and Google Translation.

Topics

Resources

License

Stars

Watchers

Forks

Languages