Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jl2/cl-libre-translate

Common Lisp package for using Libre Translate.
https://github.com/jl2/cl-libre-translate

languages libre lisp translate translation

Last synced: 5 days ago
JSON representation

Common Lisp package for using Libre Translate.

Awesome Lists containing this project

README

        

* cl-libre-translate

** About
An easy to use Common Lisp binding for the Libre Translate service.

** Using

The easiest way to use this package is with the Docker configuration from [[https://github.com/LibreTranslate/LibreTranslate][Libre Translate]].

Clone the Libre Translate repo and start the service using:

#+begin_src shell
./run.sh --port 5001
#+end_src

Once the service has downloaded all of the language files, use the library to translate text:
#+begin_src lisp :results value
(ql:quickload :cl-libre-translate)
(use-package :st-json)
(let ((result (lt:translate "This is a test!" :source "en" :target "zt")))
(getjso "translatedText" result))
#+end_src

#+RESULTS:
: 有考驗了!

To see the supported languages:
#+begin_src lisp :results output
(ql:quickload :cl-libre-translate)
(use-package :st-json)
(lt:show-languages)
#+end_src

#+RESULTS:
#+begin_example
To load "cl-libre-translate":
Load 1 ASDF system:
cl-libre-translate
; Loading "cl-libre-translate"

Urdu (ur)
Ukranian (uk)
Turkish (tr)
Thai (th)
Tagalog (tl)
Swedish (sv)
Spanish (es)
Slovenian (sl)
Slovak (sk)
Russian (ru)
Romanian (ro)
Portuguese (pt)
Polish (pl)
Persian (fa)
Norwegian (nb)
Malay (ms)
Lithuanian (lt)
Latvian (lv)
Korean (ko)
Japanese (ja)
Italian (it)
Irish (ga)
Indonesian (id)
Hungarian (hu)
Hindi (hi)
Hebrew (he)
Greek (el)
German (de)
Galician (gl)
French (fr)
Finnish (fi)
Estonian (et)
Esperanto (eo)
Dutch (nl)
Danish (da)
Czech (cs)
Chinese (traditional) (zt)
Chinese (zh)
Catalan (ca)
Bulgarian (bg)
Bengali (bn)
Basque (eu)
Azerbaijani (az)
Arabic (ar)
Albanian (sq)
English (en)
#+end_example

Parameters (and a config file) can be used to configure the Libre Translate server and API keys.
#+begin_src lisp :results value
(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))
#+end_src

#+RESULTS:
: ¡Esto es una prueba!

** Config file
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.

*** Example Config
#+begin_src javascript
{
"api-key": "",
"url": "http://localhost:5001",
"default-target": "es",
"default-source": "auto"
}
#+end_src

** API Keys Untested
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.

** License
ISC

Copyright (c) 2024 Jeremiah LaRocco