Skip to content

Add region in Translate.php #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
$endpoint = getenv("TRANSLATOR_TEXT_ENDPOINT");
}

//check the keys and endpoint management page to get the region information
$region = "eastasia";

$path = "/translate?api-version=3.0";

// Translate to German and Italian.
Expand All @@ -35,11 +38,12 @@ function com_create_guid() {
}
}

function Translate ($host, $path, $key, $params, $content) {
function Translate ($host, $path, $key, $region, $params, $content) {

$headers = "Content-type: application/json\r\n" .
"Content-length: " . strlen($content) . "\r\n" .
"Ocp-Apim-Subscription-Key: $key\r\n" .
"Ocp-Apim-Subscription-Region:$region\r\n" .
"X-ClientTraceId: " . com_create_guid() . "\r\n";

// NOTE: Use the key 'http' even if you are making an HTTPS request. See:
Expand All @@ -63,7 +67,7 @@ function Translate ($host, $path, $key, $params, $content) {
);
$content = json_encode($requestBody);

$result = Translate ($endpoint, $path, $subscription_key, $params, $content);
$result = Translate ($endpoint, $path, $subscription_key, $region, $params, $content);

// Note: We convert result, which is JSON, to and from an object so we can pretty-print it.
// We want to avoid escaping any Unicode characters that result contains. See:
Expand Down