Microsoft Translatorに登録。クラウドを利用して翻訳プログラムを簡単に作る。
Microsoft Translatorって何?
Microsoftが提供する機械翻訳のAPIです。 Windows azure(マイクロソフトが提供するクラウドサービス)のMarketplace(データの方)にあります。
機械翻訳 -> wikipedia
利用するには、Microsoft アカウントが必要です。
ということで登録しました。
月額2,000,000文字まで無料で利用できるようなので登録しました。
試してみる。
↓のような感じにAPIを試す画面が存在します。
初めまして。私はmitsugeekです。
↓↓↓Translator実行!↓↓↓
How do you do. I am mitsugeek.
単にこれだけだと、Google翻訳や、Yahoo翻訳等のWeb上の翻訳と変わりないです。
Webで利用できる翻訳サービス一覧
WEBの翻訳サービスって結構あるんですね。
何が嬉しい?
何が良いかというと自分のアプリケーションに翻訳機能を組み込める所です。 Googleも同様のサービス(Google Translate API)を行ってますが有料です。
プログラムから呼び出してみる。
手っ取り早くPHPで実行しました。
<?php const APPID = 'プライマリ アカウント キーを入力'; $input_text = '初めまして。mitsugeekです。'; $to = 'en'; $ch = curl_init('https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=%27'.urlencode($input_text).'%27&To=%27'.$to.'%27'); curl_setopt($ch, CURLOPT_USERPWD, APPID.':'.APPID); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $result = explode('<d:Text m:type="Edm.String">', $result); $result = explode('</d:Text>', $result[1]); $result = $result[0]; echo $input_text." -> ".$result;
結果。
コマンドで実行。
[root@localhost html]# php mst.php 初めまして。mitsugeekです。 -> How do you do. It is mitsugeek.