Nuix / Language-Translation-Integration

A script which integrates with third-party translation services like Google Cloud Translation or Microsoft Cognitive Services, providing a way to translate text of items in a Nuix case
Apache License 2.0
1 stars 1 forks source link

LibreTranslator on NUIX #8

Closed tribun528 closed 6 months ago

tribun528 commented 7 months ago

Hello everyone, I have NUIX Version 9.10.18. I use Language-Translation-Integration 1.3.0. I use the LibreTranslator at a Ubuntu virtual machine. LibreTranslator is arrival at the ip an I can use it with the Explorer. For exampIe, I had marked a whatsapp chat with france language. I started the script and the translation starts. The script tell me "No response received! Please try again later" What's the problem? It looks like the script can't find the http response. Can someone help me? Thanks, regards Steffen

JuicyDragon commented 7 months ago

Hello @tribun528 what are you supplying for the setting API URL?

image

tribun528 commented 7 months ago

@JuicyDragon http://172.29.78.99:5000

JuicyDragon commented 6 months ago

@tribun528 thank you for sending that. It looks like the code should make sense of that URL (just wanted to get that checked up front).

Looking at the code, it seems that for you to receive the message No response received! Please try again later, an error would likely need to occur in the method libre_translate(text). That code looks like it outputs 2 things when it runs:

Do you happen to get either of those when you run into this issue?

tribun528 commented 6 months ago

@JuicyDragon Yes, I think, too. There is the problem, but why?

JuicyDragon commented 6 months ago

Hello @tribun528 I need some more information to help troubleshoot the issue. As noted above, do you get any additional information about the error when it happens or the status code?

tribun528 commented 6 months ago

Hallo @JuicyDragon , I hoped that it is small problem. I have less time at the moment to immerse myself in the program flow. I dry it and give you a response. Thank you Regards

JuicyDragon commented 6 months ago

@tribun528 no worries, whenever you want to revisit this we can take a look at it again.

tribun528 commented 6 months ago

@JuicyDragon Fehler Translation 1.PNG

Fehler Translation 2.PNG

There is a problem in in req.body.

tribun528 commented 6 months ago

@JuicyDragon must be Ruby installed on the system to run the script? The script needs uri and net/http.

JuicyDragon commented 6 months ago

@tribun528 You should not need a separate installation of Ruby on the system. Nuix actually employs JRuby to run the Ruby scripts in Java. There is a situation where you might need to do some funny business to make Ruby gems available to it, but I believe both uri and net/http are part of the standard library and therefore available within JRuby.

JuicyDragon commented 6 months ago

@tribun528 I was looking at https://libretranslate.com/ and noticed something interesting:

image

They use /translate. Can you please try specifying API URL as http://172.29.78.99:5000/translate instead of http://172.29.78.99:5000? Looking at the code (which I am not the author of) it does not seem to automatically add that on for you so I am wondering if perhaps that is needed?

The next thing I am thinking might be needed is to explicitly specify the format as being text:

def libre_translate(text)
  http = Net::HTTP.new(@uri.host, @uri.port)
  http.use_ssl = true if @uri.instance_of? URI::HTTPS
  http.read_timeout = @settings['http_timeout'].to_i
  begin
    req = Net::HTTP::Post.new(@uri.request_uri, @headers)
    req.body = {  'q' => text,
                  'source' =>  @langs.key(@settings['translation_language_from']),
                  'target' =>  @langs.key(@settings['translation_language']),
                  'format' => 'text' # <==== New bit here
      }.to_json
    response = http.request(req)
    puts response.code
    return response_body(response)
  rescue StandardError => ex
    puts "ERROR: #{ex.message}"
  end
end

While their example includes api_key as well, I assume you only need that if you are not self-hosting.

tribun528 commented 6 months ago

@JuicyDragon I changed the code, but it don't work. I think with "translate" the code Net::HTTP::Post.new(@uri.request_uri, @headers) is not right. Can I get a print of the "req", to control the code?