To install dependencies:
bun installThis is a module, not a server. The game engine has this repository as a git submodule at
src/language-service and calls it in its own process:
import { set_logger, start_translator, translate_text } from "../language-service/src/api";
set_logger({ info: log.info, warn: log.warn, error: log.error }); // optional, defaults to console
start_translator(); // optional: load the model now instead of with the first line
const { translated_text } = await translate_text({ source_language: "en", target_languages: ["es", "fr"], source_text: "where is the mine?" });translate_text throws TranslationRequestError for a request it refuses (unknown language,
missing or too long text) and a plain Error when the translator could not answer. Importing
src/api.ts starts nothing. The Python environment below goes inside the submodule folder.
Translations come from the offline model in translator/, run on the CPU by a Python
child process (translator/serve.py). It starts with the first translation (or with
start_translator()), loads in a few seconds, and starts again with the next translation
if it stops.
The game asks once per language for each chat line, all at the same time. Requests for the same line that arrive within a few milliseconds of each other are merged, and each language runs as its own batch in parallel (6 at once, 2 CPU threads each), so six languages take about as long as one.
translator/model/: the exported model (from Frostfire Translate'sscripts/export.py)translator/ffmt/: a copy of Frostfire Translate's inference code (ffmt/__init__.py,translator.py,chat.py,langid.py,names.py)
It needs Python 3 in .venv in this folder. Create it once:
python -m venv .venv
.venv/Scripts/python -m pip install -r translator/requirements.txt # Linux/macOS: .venv/bin/pythonThe model's binary files (*.bin, *.npz, *.model) are stored with Git LFS, so run
git lfs install once before cloning. To update the model, replace translator/model/ with
Frostfire Translate's exports/latest/.
translate_text({ source_language: "en", target_languages: "es,fr,cn", source_text: "where is the mine?" })
gives translated_text as {"es": "...", "fr": "...", "cn": "..."}. Chinese is accepted as cn or zh.
To type check:
bun checkThe model in translator/model/ was trained from scratch by Frostfire Interactive. Its training data keeps its own licences and credits:
- OPUS corpora, each under its own licence (see each corpus page on opus.nlpl.eu).
- MASSIVE 1.0 (train partition): FitzGerald et al., "MASSIVE: A 1M-Example Multilingual Natural Language Understanding Dataset with 51 Typologically-Diverse Languages", 2022. Amazon, CC BY 4.0, https://github.com/alexa/massive.
- BPCC-H-Daily (English-Hindi): Gala et al., "IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Languages of India", 2023. AI4Bharat, CC BY 4.0, https://huggingface.co/datasets/ai4bharat/BPCC.
- Game translations made by the players of open-source games, each under its game's licence and its translators' copyright: Battle for Wesnoth (GPL-2.0+), Shattered Pixel Dungeon (GPL-3.0), OpenTTD (GPL-2.0), 0 A.D. (Wildfire Games, GPL-2.0+), Mindustry (GPL-3.0), Luanti (LGPL-2.1+), SuperTuxKart (GPL-3.0).
Free for noncommercial use under the PolyForm Noncommercial License 1.0.0. Every commercial use needs a paid commercial license from Frostfire Interactive. See LICENSING.md for which one applies to you.
Contributions are welcome and need a signed Contributor License Agreement; see CONTRIBUTING.md.