Skip to content

Instantly share code, notes, and snippets.

@equwal
Created May 3, 2024 08:00
Show Gist options
  • Save equwal/865272f14ec6aaae2766d9438e3e7bfc to your computer and use it in GitHub Desktop.
Save equwal/865272f14ec6aaae2766d9438e3e7bfc to your computer and use it in GitHub Desktop.
Translation has not been available in China since about one day ago #9574
-- To be used if a DNS lookup for translate.googleapis.com would fail
local Translator = require("ui/translator")
local http = require("socket.http")
Translator.getTransServer = function()
-- Change this with a usable/working IP address (that would work if added to a HOSTS file)
return "https://180.163.151.162/"
end
local orig_http_request = http.request
local hacked_http_request = function(reqt)
-- Keep this unchanged
reqt["host"] = "translate.googleapis.com"
return orig_http_request(reqt)
end
local orig_translator_loadPage = Translator.loadPage
Translator.loadPage = function(self, text, target_lang, source_lang)
http.request = hacked_http_request
local result = orig_translator_loadPage(self, text, target_lang, source_lang)
http.request = orig_http_request
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment