Card Translator is a small Flask web application that uses the OpenAI API to translate the text from wargame card images into any language (French default). The site lets you crop a part of a card, send it to the API for OCR and translation, tweak the styling and download the result as an image. Find de images of your game here https://vassalengine.org/library/projects
These instructions assume you want to keep the project on a USB drive and run it on different machines without installing anything globally.
- Copy the repository.
- Install Python 3.10+ https://www.python.org/downloads/windows/ download the exe installer for simplicity. 3. Check the PATH option
- Open a terminal and create a virtual environment inside the project folder:
python -m venv venv
- Activate the environment (optionnal):
- On Windows:
venv\\Scripts\\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
- Install the Python dependencies:
pip install flask openai
- Create a file
wargame_site/API_KEY.txt
containing your OpenAI API key (the key must be on a single line with no quotes). - The temporary image
card.png
and your API key are ignored by Git and remain local to your USB drive.
From the project root:
cd wargame_site
python app.py
The Flask development server starts on http://localhost:5000
.
The backend reads the API key from wargame_site/API_KEY.txt
when it launches. Make sure the file exists before starting the server. Each machine that runs the app must have network access to the OpenAI API.
The actual OCR + translation happens in wargame_site/backend_translate.py
through a prompt sent to OpenAI. To translate cards into another language, open that file and replace the French instructions in the prompt
string with your desired target language.
The prompt also contains a bullet list of vocabulary rules. You can add or modify entries to force specific translations or to forbid translation of certain words so key game terms stay in their original language. This keeps terminology consistent from card to card.
Example additions:
- "Victory Points" → "Victory Points" # keep term untranslated
- "stack" → "pila" # custom translation
- Open
http://localhost:5000
in a browser. - Use the file picker to import one or more card images; thumbnails appear in the left column.
- Click a thumbnail to preview it. Drag to define a highlight box around the area to translate.
- Press Enter to send the selection to the OpenAI API. The translated HTML appears on the right and is shown on top of the selected area.
- Adjust font size, background colour, margins or paste your own HTML using the controls on the right.
- Use Validate to save the translation, Download to export the current preview, or Download all to export every saved image.
- Reset clears the selection and lets you choose another area of the card.
This project does not currently include a license file; treat it as all rights reserved by the author.