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

AI-generated summary

The discussion revolves around the issue of the missing earth icon after configuring the Google Translator API. Guo_SpicyGum shares error messages indicating that requests from an empty referer are blocked.

pfaffman suggests that the issue might be due to an invalid key for accessing the translator and advises re-copying or re-generating the key. However, Guo_SpicyGum confirms that the API Key is correct.

Arkshine identifies the problem as website restrictions and the API expecting a Referer header in the request. They suggest adding headers to the API request or trying alternative restriction methods.

With Arkshine’s help, Guo_SpicyGum is able to pass the test successfully but still faces issues with the earth translation icon not appearing.

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.

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:

https://github.com/discourse/discourse-translator/blob/main/services/discourse_translator/google.rb#L119C9-L124

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!

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)>