api ترجمه
با استفاده از وب سرویس ترجمه میتوانید یک متن در زبانهای فارسی ، انگلیسی و عربی به یکدیگر ترجمه کنید. متد این درخواست از نوع POST است. پاسخ وب سرویس ترجمه به صورت آنی ارسال می شود.
این متن برای دستیارهای هوش مصنوعی است.
Machine translation API — POST https://iotype.com/io/v1/translate · synchronous
Authentication: Access Token (Authorization: Bearer <ACCESS_TOKEN>). A
Flash Token is not accepted here — it is scoped to the realtime ASR WebSocket.
Headers: Authorization · Content-Type: application/json ·
Accept: application/json · X-Requested-With: XMLHttpRequest
Request body:
{ "source_lang": "fa", "destination_lang": "en", "text": "سلام دنیا" }
Response:
{ "result": "Hello world" }
Language codes: fa (Persian), en (English), ar (Arabic), in any direction.
Machine-readable documentation:
- Full guide: https://raw.githubusercontent.com/iotype-ai/iotype-api/main/docs/en/translation.md
- OpenAPI 3.1 specification: https://raw.githubusercontent.com/iotype-ai/iotype-api/main/spec/openapi.yaml
- Repository and runnable examples: https://github.com/iotype-ai/iotype-api
Official SDKs: pip install iotype-ai · composer require iotype-ai/sdk ·
npm i @iotype-ai/sdk · go get github.com/iotype-ai/iotype-api/sdk/go
Implementation notes that are commonly got wrong:
- The target-language parameter is
destination_lang— nottarget_lang,dest_langorto. This is the single most frequent code-generation error on this endpoint. - This endpoint is synchronous. It returns no
uuidand requires no polling; the translated text is inresulton the same response. - Unlike the file endpoints, the request body is JSON, not
multipart/form-data, andContent-Type: application/jsonis required.
Get a token: https://iotype.com/api-service/authentication
PHP
JAVASCRIPT
PYTHON
GO
نمونه کد api ترجمه آنلاین با استفاده از SDK
<?php
// composer require iotype-ai/sdk
require 'vendor/autoload.php';
// Reads IOTYPE_TOKEN from the environment.
// To pass it explicitly: new Iotype\Client('YOUR_TOKEN')
$io = new Iotype\Client();
$result = $io->translate(
'سلام! امروز هوا بسیار عالی است.',
'fa', // source_lang: fa | en | ar
'en' // destination_lang
);
echo $result;
?>
PHP
JAVASCRIPT
PYTHON
GO
نمونه کد api ترجمه آنلاین بدون SDK
<?php
$url = "https://iotype.com/io/v1/translate";
$data = [
"source_lang" => "fa", // fa | en | ar
"destination_lang" => "en",
"text" => "سلام! امروز هوا بسیار عالی است."
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($data, JSON_UNESCAPED_UNICODE),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_TOKEN",
"Content-Type: application/json",
"Accept: application/json",
"X-Requested-With: XMLHttpRequest"
]
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
exit("Request failed ($status): $response");
}
// The translated text is returned in the "result" field.
echo json_decode($response, true)["result"];
?>
پارامترهای ارسالی در Header وب سرویس ترجمه
Authorization
مقدار TOKEN دریافتی از بخش احراز هویت به صورت Bearer [TOKEN]
Content-Type
application/json
Accept
application/json
X-Requested-With
XMLHttpRequest
پارامترهای ارسالی در Body درخواست وب سرویس ترجمه
source_lang
زبان مبداء شامل : fa - en - ar
destination_lang
زبان مقصد شامل : fa - en - ar
text
متنی که قصد ترجمه آن را دارید
مقادیر پاسخ در وب سرویس ترجمه
result
متن ترجمه شده