Artikash / Textractor

Extracts text from video games and visual novels. Highly extensible.
GNU General Public License v3.0
2.13k stars 205 forks source link

Request: Allow the selection of API region and custom endpoint in Bing Translate Plugin #361

Open samcsk opened 4 years ago

samcsk commented 4 years ago

Currently, the plugin is assuming the global region (by omitting in the header field Ocp-Apim-Subscription-Region) when contacting the API endpoint. This results in the return of

Error while translating: {"error":{"code":401000,"message":"The request is not authorized because credentials are missing or invalid."}}

whenever the endpoint is set to be any other regions.

From the official docs, the currently available regions are

australiaeast, brazilsouth, canadacentral, centralindia, centralus, centraluseuap, eastasia, eastus, eastus2, francecentral, japaneast, japanwest, koreacentral, northcentralus, northeurope, southcentralus, southeastasia, uksouth, westcentralus, westeurope, westus, westus2, and southafricanorth.

Moreover, the API can also be accessed via custom endpoints (https://\<your-custom-domain>.cognitiveservices.azure.com/).

It would be nice if the plugin includes fields for the input of these two information.

KiruyaMomochi commented 2 years ago

Here is a tricky workaround. You can set API key to something like

<Your API Key>
Ocp-Apim-Subscription-Region: <Region>

Since we can't type linebreak \n directly in GUI, we need to first write these two lines in somewhere like notepad, then copy them and paste to Textractor. The linebreak looks like a space, but it's actually linebreak. (You can copy it back to notepad to verify it)

This trick works because Textractor just joins our input into headers: https://github.com/Artikash/Textractor/blob/3e283975c8f0cf1bb8f1818e18e909196970c96b/extensions/bingtranslate.cpp#L209

image