Why is there no earth icon after I configured the Google Translator API?

Why is there no earth icon after I configured the Google Translator API?

root@talk:/data/discourse# ./launcher enter app
x86_64 arch detected.
WARNING: containers/app.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/app.yml
root@talk-app:/var/www/discourse# rails c
[1] pry(main)> DiscourseTranslator::Google.detect(Post.last)
DiscourseTranslator::TranslatorError: {"error"=>{"code"=>403, "message"=>"Requests from referer <empty> are blocked.", "errors"=>[{"message"=>"Requests from referer <empty> are blocked.", "domain"=>"global", "reason"=>"forbidden"}], "status"=>"PERMISSION_DENIED", "details"=>[{"@type"=>"type.googleapis.com/google.rpc.ErrorInfo", "reason"=>"API_KEY_HTTP_REFERRER_BLOCKED", "domain"=>"googleapis.com", "metadata"=>{"service"=>"translate.googleapis.com", "consumer"=>"projects/390801787023"}}]}}
from /var/www/discourse/plugins/discourse-translator/services/discourse_translator/google.rb:134:in `result'



Is there anyone who can support me?

It looks like you have not supplied a valid key for accessing the translator. I would check that you have supplied payment and re-copy or re-generate the key.

2 Likes

okay, is my request test method correct?

 DiscourseTranslator::Google.detect(Post.last)

I have provided the correct API Key, but still get the error:

[8] pry(main)> DiscourseTranslator::Google.detect(Post.last)
DiscourseTranslator::TranslatorError: {"error"=>{"code"=>403, "message"=>"Requests from referer <empty> are blocked.", "errors"=>[{"message"=>"Requests from referer <empty> are blocked.", "domain"=>"global", "reason"=>"forbidden"}], "status"=>"PERMISSION_DENIED", "details"=>[{"@type"=>"type.googleapis.com/google.rpc.ErrorInfo", "reason"=>"API_KEY_HTTP_REFERRER_BLOCKED", "domain"=>"googleapis.com", "metadata"=>{"consumer"=>"projects/390801787023", "service"=>"translate.googleapis.com"}}]}}
from /var/www/discourse/plugins/discourse-translator/services/discourse_translator/google.rb:134:in `result'

I filled in the google translator api key, but it doesn’t work properly, please help solve it!


root@talk:/data/discourse# ./launcher enter app
x86_64 arch detected.
WARNING: containers/app.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/app.yml
root@talk-app:/var/www/discourse# rails c
[1] pry(main)> DiscourseTranslator::Google.detect(Post.last)
DiscourseTranslator::TranslatorError: {"error"=>{"code"=>403, "message"=>"Requests from referer <empty> are blocked.", "errors"=>[{"message"=>"Requests from referer <empty> are blocked.", "domain"=>"global", "reason"=>"forbidden"}], "status"=>"PERMISSION_DENIED", "details"=>[{"@type"=>"type.googleapis.com/google.rpc.ErrorInfo", "reason"=>"API_KEY_HTTP_REFERRER_BLOCKED", "domain"=>"googleapis.com", "metadata"=>{"service"=>"translate.googleapis.com", "consumer"=>"projects/390801787023"}}]}}
from /var/www/discourse/plugins/discourse-translator/services/discourse_translator/google.rb:134:in `result'

my request test method correct?

You have defined website restrictions, and the API expects to see a Referer header in the API request, which seems explicitly required here:

To fix it, you would probably need the following:

headers: {
    "Content-Type" => "application/x-www-form-urlencoded",
    "Referer" => Discourse.base_url
  }

In other words, the issue is not caused by your end.

What you can do is either:

  • Try restriction by IP
  • Disable the restriction until it’s fixed in the plugin

Hope that helps!

1 Like

Thank you very much for your help, with the above I have been able to pass the test successfully. But I found that I still have the earth translation icon.

root@talk-app:/var/www/discourse/plugins/discourse-translator/services/discourse_translator# rails c
[1] pry(main)> DiscourseTranslator::Google.detect(Post.last)
=> "en"
[2] pry(main)>