Plugin LibreTranslate -- API de traduction gratuite et open source

Continuing the discussion from Discourse Translator:

LibreTranslate - Github project page
Project discussion at https://community.libretranslate.com/

Free and Open Source Machine Translation API. 100% self-hosted, offline capable and easy to setup. Powered by the open source Argos Translate

Discourse Installation

copy-pasted from the Github readme

You can use this discourse translator plugin to translate Discourse topics. To install it simply modify /var/discourse/containers/app.yml :

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/LibreTranslate/discourse-translator
	  ...

Then issue ./launcher rebuild app . From the Discourse’s admin panel then select “LibreTranslate” as a translation provider and set the relevant endpoint configurations.

6 « J'aime »

I’m not the author, but just discovered this amazing plugin. Afaik no one has mentioned it on the forum. This will need to be turned into a plugin topic and hopefully we can get the dev on this chat… unless I’m totally missing where this plugin is already listed in meta.*

2 « J'aime »

J’ai essayé de configurer cela, mais à la dernière étape (obtenir une traduction), j’ai échoué avec le message d’erreur suivant :

Une erreur s'est produite : #<Excon::Response:0x00007f25419e6818 @data={:body=>"\u003c!doctype html\u003e\n\u003chtml lang=en\u003e\n\u003ctitle\u003e405 Method Not Allowed\u003c/title\u003e\n\u003ch1\u003eMethod Not Allowed\u003c/h1\u003e\n\u003cp\u003eThe method is not allowed for the requested URL.\u003c/p\u003e\n", :cookies=>[], :host=>"172.17.0.1", :headers=>{"Access-Control-Allow-Credentials"=>"true", "Access-Control-Allow-Headers"=>"Authorization, Content-Type", "Access-Control-Allow-Methods"=>"GET, POST", "Access-Control-Allow-Origin"=>"*", "Access-Control-Expose-Headers"=>"Authorization", "Access-Control-Max-Age"=>"1728000", "Allow"=>"HEAD, GET, OPTIONS", "Content-Length"=>"153", "Content-Type"=>"text/html; charset=utf-8", "Date"=>"Sat, 17 Dec 2022 11:18:27 GMT", "Server"=>"waitress"}, :path=>"//languages", :port=>5000, :status=>405, :status_line=>"HTTP/1.1 405 METHOD NOT ALLOWED\r\n", :reason_phrase=>"METHOD NOT ALLOWED", :remote_ip=>"172.17.0.1", :local_port=>50848, :local_address=>"172.17.0.3"}, @body="\u003c!doctype html\u003e\n\u003chtml lang=en\u003e\n\u003ctitle\u003e405 Method Not Allowed\u003c/title\u003e\n\u003ch1\u003eMethod Not Allowed\u003c/h1\u003e\n\u003cp\u003eThe method is not allowed for the requested URL.\u003c/p\u003e\n", @headers={"Access-Control-Allow-Credentials"=>"true", "Access-Control-Allow-Headers"=>"Authorization, Content-Type", "Access-Control-Allow-Methods"=>"GET, POST", "Access-Control-Allow-Origin"=>"*", "Access-Control-Expose-Headers"=>"Authorization", "Access-Control-Max-Age"=>"1728000", "Allow"=>"HEAD, GET, OPTIONS", "Content-Length"=>"153", "Content-Type"=>"text/html; charset=utf-8", "Date"=>"Sat, 17 Dec 2022 11:18:27 GMT", "Server"=>"waitress"}, @status=405, @remote_ip="172.17.0.1", @local_port=50848, @local_address="172.17.0.3">

J’ai configuré un conteneur Docker avec docker run -d --restart unless-stopped -ti -p 5000:5000 --name="libretranslate" libretranslate/libretranslate qui semblait bien fonctionner pour moi selon la documentation et j’ai configuré translator libretranslate endpoint sur http://172.17.0.1:5000 (l’IP est l’IP de l’hôte Docker).

Selon le message d’erreur, Discourse peut également se connecter à LibreTranslate, mais quelque chose ne fonctionne pas.

Des idées ?

C’est résolu :slight_smile: : Problem with LibreTranslate as Docker for Discourse - #3 by pierotofy - LibreTranslate API - LibreTranslate Community

Vous devez mettre à jour vers la dernière version Github du plugin Discourse.

2 « J'aime »

@Roi pourriez-vous s’il vous plaît aider à clarifier comment cela est configuré. Je suis confus. J’ai trouvé mon adresse IP de conteneur Docker en utilisant sudo docker inspect libretranslate

D’après votre article lié, le point de terminaison de l’API est-il traité comme :

http://dockerip:5000

sans clé API nécessaire ? J’exécute libretranslate dans un conteneur aux côtés de Discourse. Merci !

@sunjam oui, j’utilise :

http://172.17.0.1:5000/

Où 172.17.0.1 est l’IP du conteneur Docker Libretranslate.

Et je n’utilise pas de clé API.

2 « J'aime »

@Roi Merci, voici votre commande d’exécution :

docker run -d --restart unless-stopped -ti -p 5000:5000 --name="libretranslate" libretranslate/libretranslate

D’une manière ou d’une autre oui :

docker run -d --restart unless-stopped -ti -p 5000:5000 -e LT_LOAD_ONLY="en,de,fr,it,es,pt,nl,da,sv,pl,cs,ru" --name="libretranslate" libretranslate/libretranslate

Signalant également à Libretranslate ici, mais je rencontre une erreur et un avertissement lors de la tentative d’utilisation de Libretranslate avec les applications Multilingual et Translator.

Erreur de tâche : délai d'attente de connexion/écriture dépassé
Backtrace

/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/socket.rb:317:in `select_with_timeout'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/socket.rb:163:in `rescue in block in connect'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/socket.rb:144:in `block in connect'
/usr/local/lib/ruby/3.2.0/resolv.rb:111:in `each_address'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/socket.rb:134:in `connect'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/socket.rb:51:in `initialize'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/connection.rb:477:in `new'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/connection.rb:477:in `socket'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/connection.rb:121:in `request_call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/excon-0.104.0/lib/excon/middlewares/mock.rb:57:in `request_call'

[details=“DistributedMutex("detect_translation_15"): détenu trop longtemps, maximum attendu : 60 secondes, a pris 1 seconde supplémentaire”]

DistributedMutex("detect_translation_15"): détenu trop longtemps, maximum attendu : 60 secondes, a pris 1 seconde supplémentaire

Backtrace

/var/www/discourse/lib/distributed_mutex.rb:103:in `warn'
/var/www/discourse/lib/distributed_mutex.rb:57:in `ensure in block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:64:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize'
/var/www/discourse/plugins/discourse-translator/plugin.rb:98:in `execute'
/var/www/discourse/app/jobs/base.rb:292:in `block (2 levels) in perform'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rails_multisite-5.0.0/lib/rails_multisite/connection_management.rb:82:in `with_connection'
/var/www/discourse/app/jobs/base.rb:279:in `block in perform'

[/details]

1 « J'aime »

Je continue de tester le plugin Libretranslate avec les instances gratuites qu’ils recommandent. Je vois cette erreur dans tests-passés

[details=" Exception de tâche : {"error"=\u003e"Requête invalide : paramètre q manquant"} "]

Message (2 copies signalées)
Exception de tâche : {"error"=>"Requête invalide : paramètre q manquant"}


Backtrace

/var/www/discourse/plugins/discourse-translator/services/discourse_translator/libretranslate.rb:150:in `result'
/var/www/discourse/plugins/discourse-translator/services/discourse_translator/libretranslate.rb:84:in `detect'
/var/www/discourse/plugins/discourse-translator/plugin.rb:99:in `block in execute'
/var/www/discourse/lib/distributed_mutex.rb:53:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize'
/var/www/discourse/plugins/discourse-translator/plugin.rb:98:in `execute'
/var/www/discourse/app/jobs/base.rb:292:in `block (2 levels) in perform'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rails_multisite-5.0.0/lib/rails_multisite/connection_management.rb:82:in `with_connection'

[/details]