An easy to use Common Lisp binding for the Libre Translate service.
The easiest way to use this package is with the Docker configuration from Libre Translate.
Clone the Libre Translate repo and start the service using:
./run.sh --port 5001
Once the service has downloaded all of the language files, use the library to translate text:
(ql:quickload :cl-libre-translate)
(use-package :st-json)
(let ((result (lt:translate "This is a test!" :source "en" :target "zt")))
(getjso "translatedText" result))
To see the supported languages:
(ql:quickload :cl-libre-translate)
(use-package :st-json)
(lt:show-languages)
Parameters (and a config file) can be used to configure the Libre Translate server and API keys.
(ql:quickload :cl-libre-translate)
(use-package :st-json)
(let* ((lt:*libre-translate-url* "https://libretranslate.com")
(lt:*api-key* "Some API key")
(result (lt:translate "This is a test!" :source "en" :target "es")))
(getjso "translatedText" result))
Config settings can also be read from a JSON file pointed to by the lt:*config-file*
parameter. The
default location is in the package directory. The default configuration is shown below.
{
"api-key": "",
"url": "http://localhost:5001",
"default-target": "es",
"default-source": "auto"
}
So far I’ve only used this package against a local Docker service, without API keys. I have little use for the API keys right now, so I don’t plan to test them. If they are not working, please let me know, and I’ll try to fix them. A PR fixing the problem would also be welcome.
ISC
Copyright (c) 2024 Jeremiah LaRocco <jeremiah_larocco@fastmail.com>