~eightytwo/translator

A service to translate a word into many other languages.
a83b00b1 — eightytwo 8 months ago
Update CORS list
b90c305b — eightytwo 8 months ago
Fix Python version formatting
5cb364c7 — eightytwo 8 months ago
Bump Python version

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~eightytwo/translator
read/write
git@git.sr.ht:~eightytwo/translator

You can also use your local clone with git send-email.

#translator

translator is a tool that shows the translation of a word in many other languages.

Screenshot of translator

#Motivation

This application was originally written in 2012 to gain some familiarity with Node.js. It seemed like a suitable application to resurrect in order to explore some different client and server technologies that I haven't had a chance to work with.

In this repository there are three client and three server implementations.

Client

  1. Vue.js
  2. React
  3. ClojureScript

Server

  1. Python
  2. Racket
  3. Clojure

As I only have prior experience with Python, the other implementations may very well range from rough around the edges to a pile spaghetti.

#Requirements

Aside from the languages and their tooling, the only other requirement is to have an API key for using Microsoft's Translator Text API. Once you have this key, set it as the value of the environment variable AZURE_TRANSLATOR_KEY. Each server implementation will read this environment variable.

#Running

The following instructions describe how to run this application locally using each implementation.

Before we get implementation specific, we'll need the source code, so go ahead and clone this repository.

Then jump to any section below for instructions on how to run a particular implementation.

  1. Servers
  2. Clients

Note Each client tries to connect to the server on port 8181 and each server listens on port 8181. The Python and Racket server implementations can have their port set by command line and an environment variable, respectively, but the Clojure server implementation and client implementations are hardcoded. Tidying this up will be an additional exercise to learn about configuration best practices.

#Servers

#Python

The Python server implementation is written in Python 3 and makes use of the FastAPI web framework. It is assumed you have Python 3 installed.

First of all, change to the server-python directory.

$ cd server-python

Then create a virtual environment with venv and activate it.

$ python3 -m venv env
$ . env/bin/activate

Now we can install the third-party packages.

(env) $ pip install -r requirements.txt

Finally, the last step is to run the server.

(env) $ uvicorn app:app --reload --port 8181
#Racket

If you don't have Racket installed it's very simple. Head on over to racket-lang.org and follow the download and installation instructions.

Once installed, change to the server-racket directory.

$ cd server-racket

Then just run the program.

$ racket server.rkt
#Clojure

In order to run the Clojure server implementation you will need Clojure and Leiningen.

  1. The Getting Started page on the Clojure website has very simple instructions outlining how to install Clojure.

  2. Similarly, the Install section of the Leiningen website has very simple installation instructions.

Once you have both Clojure and Leiningen installed on your system, change to the clojure directory.

$ cd clojure

Then start the application. Leiningen will fetch all required dependencies which may take a little time.

$ lein run

#Clients

#Vue.js

Change to the client-vue directory.

$ cd client-vue

Install the dependencies with yarn.

$ yarn install

Finally, run the application.

$ yarn serve

The application will be served at http://localhost:8080/.

#React

Change to the client-react directory.

$ cd client-react

Install the dependencies with yarn.

$ yarn install

Finally, run the application.

$ yarn start

The application will be served at http://localhost:3000/.

#ClojureScript

Change to the clojure directory.

$ cd clojure

Start the application.

$ lein fig:build

The application will be served at http://localhost:9500/.