Problem with LibreTranslate as Docker for Discourse

Hello,

I tried to set this up but in the final step (getting a translation) I fail with the following error message:

An error occurred: #<Excon::Response:0x00007f25419e6818 @data={:body=>"<!doctype html>\n<html lang=en>\n<title>405 Method Not Allowed</title>\n<h1>Method Not Allowed</h1>\n<p>The method is not allowed for the requested URL.</p>\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="<!doctype html>\n<html lang=en>\n<title>405 Method Not Allowed</title>\n<h1>Method Not Allowed</h1>\n<p>The method is not allowed for the requested URL.</p>\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">

I set up a docker container with docker run -d --restart unless-stopped -ti -p 5000:5000 --name="libretranslate" libretranslate/libretranslate which seemed to be fine for me according to the docs and set up translator libretranslate endpoint to http://172.17.0.1:5000 (the IP is the docker host IP).

According to the error message Discourse can also connect to LibreTranslate but something is not working.

Any ideas?

Regards,
Roi

Hey Roi :wave:

it looks like the /translate endpoint used to respond to POST, but that was changed with: /languages should be only available for GET · LibreTranslate/LibreTranslate@d7377d1 · GitHub

Ok, I’ve just updated the code on https://github.com/LibreTranslate/discourse-translator. Try to install the latest copy of the plugin from there? :pray:

cd /var/discourse
./launcher rebuild app
1 Like

Great, it works now! Thank you so much! :slight_smile:

About the Docker options: My two Discourse forums run in German language (mostly). So what would I especially setup as default frontend language (and also as default target language)? German (and maybe English)?

-e LT_FRONTEND_LANGUAGE_SOURCE="de"
-e LT_FRONTEND_LANGUAGE_TARGET="en"

No need to specify a default language, it should just work ™

1 Like