CloudTranslateAPI Reference
CloudTranslateAPI は、高性能なテキスト翻訳を提供する RESTful API です。シンプルなインターフェースで、多言語間の翻訳を簡単に統合できます。機械学習モデルを活用して、正確かつ効率的な翻訳を実現します。
https://cloudtranslate-mixederapi.mixeder.com/
async function translateText(apiKey, text, sourceLang, targetLang) {
const apiUrl = 'https://cloudtranslate-mixederapi.mixeder.com/';
const body = {
key: apiKey,
text: text || 'Tell me a joke about Cloudflare',
source: sourceLang || 'en',
target: targetLang || 'fr',
};
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error(`API error: ${response.statusText}`);
}
const data = await response.json();
console.log('Translation:', data.translation.result);
return data.translation.result;
} catch (error) {
console.error('Error during translation:', error.message);
throw error;
}
}
// 使用例
translateText('your-api-key', 'Hello, world!', 'en', 'es')
.then((result) => console.log('Translated text:', result))
.catch((err) => console.error('Translation failed:', err));
import requests
def translate_text(api_key, text, source_lang, target_lang):
api_url = 'https://cloudtranslate-mixederapi.mixeder.com/'
payload = {
"key": api_key,
"text": text or "Tell me a joke about Cloudflare",
"source": source_lang or "en",
"target": target_lang or "fr",
}
try:
response = requests.post(api_url, json=payload)
response.raise_for_status()
data = response.json()
print("Translation:", data["translation"]["result"])
return data["translation"]["result"]
except requests.exceptions.RequestException as e:
print("Error during translation:", e)
raise
# 使用例
translate_text("your-api-key", "Hello, world!", "en", "es")
curl -X POST https://cloudtranslate-mixederapi.mixeder.com/ \
-H "Content-Type: application/json" \
-d '{
"key": "your-api-key",
"text": "Hello, world!",
"source": "en",
"target": "es"
}'