import requests
API_URL = "https://dika.irres.ir/api/v1/translate"
HEADERS = {
"X-API-Key": "dika_dev_your_key_here",
"Content-Type": "application/json"
}
payload = {
"q": [
"Artificial intelligence is revolutionizing global communications.",
"Real-time edge neural translation."
],
"source": "en",
"target": "fa",
"tone": "academic"
}
resp = requests.post(API_URL, json=payload, headers=HEADERS)
data = resp.json()
if data.get("success"):
for item in data["data"]["translations"]:
print("ترجمه:", item["translatedText"])
// npm install axios (یا استفاده از Fetch بومی Node.js 18+)
const axios = require('axios');
async function translate() {
const res = await axios.post('https://dika.irres.ir/api/v1/translate', {
q: 'High-performance microservices architecture with Dika API',
source: 'en',
target: 'fa',
tone: 'technical'
}, {
headers: {
'X-API-Key': 'dika_dev_your_key_here',
'Content-Type': 'application/json'
}
});
console.log('نتیجه:', res.data.data.translations[0].translatedText);
}
translate();
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
struct ResponseBuffer {
char *data;
size_t size;
};
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t total_size = size * nmemb;
struct ResponseBuffer *mem = (struct ResponseBuffer *)userp;
char *ptr = realloc(mem->data, mem->size + total_size + 1);
if (!ptr) return 0;
mem->data = ptr;
memcpy(&(mem->data[mem->size]), contents, total_size);
mem->size += total_size;
mem->data[mem->size] = 0;
return total_size;
}
int main(void) {
CURL *curl;
CURLcode res;
struct ResponseBuffer buffer = { .data = malloc(1), .size = 0 };
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: dika_dev_your_key_here");
const char *payload = "{\"q\":\"Universal AI Translation Engine\",\"source\":\"en\",\"target\":\"fa\",\"tone\":\"technical\"}";
curl_easy_setopt(curl, CURLOPT_URL, "https://dika.irres.ir/api/v1/translate");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&buffer);
res = curl_easy_perform(curl);
if (res == CURLE_OK) {
printf("پاسخ سرور دیکا:\n%s\n", buffer.data);
} else {
fprintf(stderr, "خطا در برقراری ارتباط: %s\n", curl_easy_strerror(res));
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
free(buffer.data);
}
curl_global_cleanup();
return 0;
}
#include <iostream>
#include <string>
#include <curl/curl.h>
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main() {
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL* curl = curl_easy_init();
if (curl) {
std::string response;
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: dika_dev_your_key_here");
std::string payload = R"({
"q": "Cutting-edge neural translation and enterprise microservices.",
"source": "en",
"target": "fa",
"tone": "academic"
})";
curl_easy_setopt(curl, CURLOPT_URL, "https://dika.irres.ir/api/v1/translate");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
CURLcode res = curl_easy_perform(curl);
if (res == CURLE_OK) {
std::cout << "پاسخ سرور دیکا:\n" << response << std::endl;
} else {
std::cerr << "خطای اتصال: " << curl_easy_strerror(res) << std::endl;
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "dika_dev_your_key_here");
var payload = new
{
q = "Universal AI Translation Engine for Developers",
source = "en",
target = "fa",
tone = "academic"
};
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://dika.irres.ir/api/v1/translate", content);
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);
}
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class DikaClient {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"q": "Next-generation multilingual translation and localization",
"source": "en",
"target": "fa",
"tone": "academic"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://dika.irres.ir/api/v1/translate"))
.header("Content-Type", "application/json")
.header("X-API-Key", "dika_dev_your_key_here")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Status: " + response.statusCode());
System.out.println("Body: " + response.body());
}
}
<?php
$ch = curl_init('https://dika.irres.ir/api/v1/translate');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: dika_dev_your_key_here',
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'q' => 'توسعه نرمافزارهای یکپارچه ابری با موتور دیکا',
'source' => 'fa',
'target' => 'en',
'tone' => 'formal'
])
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://dika.irres.ir/api/v1/translate"
payload, _ := json.Marshal(map[string]interface{}{
"q": "Cloud native microservices with resilient AI pipelines",
"source": "en",
"target": "fa",
"tone": "technical",
})
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
req.Header.Set("X-API-Key", "dika_dev_your_key_here")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let mut headers = HeaderMap::new();
headers.insert("X-API-Key", HeaderValue::from_static("dika_dev_your_key_here"));
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
let payload = json!({
"q": "High safety, memory-safe backend integration with Rust and Dika AI",
"source": "en",
"target": "fa",
"tone": "academic"
});
let res = client.post("https://dika.irres.ir/api/v1/translate")
.headers(headers)
.json(&payload)
.send()
.await?
.text()
.await?;
println!("{:#?}", res);
Ok(())
}
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> translateText() async {
final url = Uri.parse('https://dika.irres.ir/api/v1/translate');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'dika_dev_your_key_here',
},
body: jsonEncode({
'q': 'Smart cross-platform mobile translation with Dika AI',
'source': 'en',
'target': 'fa',
'tone': 'conversational',
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('ترجمه: ${data["data"]["translations"][0]["translatedText"]}');
}
}
# Linux & macOS Terminal (Bash / Zsh)
curl -X POST "https://dika.irres.ir/api/v1/translate" \
-H "Content-Type: application/json" \
-H "X-API-Key: dika_dev_your_key_here" \
-d '{
"q": "Fast translation via terminal CLI",
"source": "en",
"target": "fa",
"tone": "general"
}'
# Windows PowerShell (curl.exe یا Invoke-RestMethod)
curl.exe -X POST "https://dika.irres.ir/api/v1/translate" `
-H "Content-Type: application/json" `
-H "X-API-Key: dika_dev_your_key_here" `
-d '{\"q\": \"Fast translation via Windows PowerShell\", \"source\": \"en\", \"target\": \"fa\", \"tone\": \"general\"}'
# روش بومی PowerShell (Invoke-RestMethod):
# $body = @{ q = "Fast translation"; source = "en"; target = "fa"; tone = "general" } | ConvertTo-Json
# Invoke-RestMethod -Uri "https://dika.irres.ir/api/v1/translate" -Method Post -Headers @{ "X-API-Key" = "dika_dev_your_key_here" } -Body $body -ContentType "application/json"
:: Windows Command Prompt (CMD)
curl.exe -X POST "https://dika.irres.ir/api/v1/translate" ^
-H "Content-Type: application/json" ^
-H "X-API-Key: dika_dev_your_key_here" ^
-d "{\"q\": \"Fast translation via Windows CMD\", \"source\": \"en\", \"target\": \"fa\", \"tone\": \"general\"}"
// دریافت کلمه به کلمه ترجمه به صورت استریم زنده (Server-Sent Events)
async function streamTranslation(text) {
const response = await fetch('https://dika.irres.ir/api/v1/translate/stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'dika_dev_your_key_here'
},
body: JSON.stringify({ text, source: 'en', target: 'fa' })
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
console.log('قطعه استریم:', chunk);
}
}
رندر بلادرنگ و راستچین با هایلایت استاندارد کدهای برنامهنویسی و جداول سازمانی